loopbackio / loopbackio/loopback-next
Exposing GraphQL APIs with nested queries enabled using OASGraph.
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 27
Description
Hello, I am exposing GraphQL API for my current project using OASGraph, and am having issues querying for nested models when tested on GraphiQL.
What I Did
I currently have three models: User, GameProfile, and Game. Their relationships are as follows:
- A User has many GameProfiles.
- A GameProfile belongs to User and Game.
- A Game has many GameProfiles.
It is my understanding that simply typing into the console npx oasgraph http://localhost:3000/openapi.json provided by the tutorial won't expose nested relationships, since OASGraph's default option for addSubOperation is false.
Therefore, after creating a GET route for /users/{id}/game-profiles for retrieving GameProfile model instances belong to User, and testing that it works as expected, I created my own OASGraph server following the guideline, creating the necessary schema as follows :
const oas = JSON.parse(
await request.get('http://localhost:3000/openapi.json')
);
const { schema, report } = await createGraphQlSchema(oas, {
addSubOperations: true
});
Current Behavior
Starting the server and navigating to GraphiQL I ran into two issues :
- The query won't recognize "users" as valid, and recommends that I query for "user" "users2" or "userCount."
- The output for the query is null.
query{
users2 {
gameProfiles {
gameProfileId
gameProfileNickname
statusId
createdAt
userId
gameId
}
}
}
{
"data": {
"users2": [
{
"gameProfiles": null
}
]
}
}
Comment
Would anyone have any idea as to why this might be happening? Your help is appreciated!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue in GraphiQL using the generated openapi.json and the createGraphQlSchema call with addSubOperations enabled. Inspect how the users2 operation resolves the /users/{id}/game-profiles route; done means a nested users query is recognized and returns its gameProfiles instead of null.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, openapi, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100