Open esoodev opened 5 years ago
@esoodev please create a small application we can use to reproduce the issue locally. See https://loopback.io/doc/en/contrib/Reporting-issues.html#loopback-4x-bugs. You can use examples/todo-list
as the app to start from, it comes with a has-many relation between TodoList and Todo models.
@bajtos If it's alright with you, I am attaching a link to the project, since it's quite small and can be used to observe the problem mentioned above.
npm install && npm start
then navigate to GraphiQL with example query
Thank you for the link. I was able to run your app and reproduce the issue. Kind of. I am confused about where users2
is coming from and also how is it possible that gameProfile
is including a nested user
data inside?
Anyhow. I think to make the relations work, we need to include "links" in the description of REST API methods.
Quoting from https://github.com/strongloop/oasgraph#characteristics:
Nested data Links defined in the OAS are used to compose data definitions. Furthermore, hierarchical path structures can be used to nest data via the addSubOperations option.
Link to OpenAPI spec:
link
section, see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#response-objectWhat to try: in your controllers, enhance your response specifications with a links section pointing to relevant endpoints. Once we figure out the right way how to make this work, it would be great to update our todo-list example accordingly and describe this solution in our docs too.
@bajtos Thank you for the link to the OpenAPI spec. I edited my response specifications accordingly as you advised. I can query individual GameProfile
with its User
successfully. Regarding my attempt to query a list of GameProfile
s with their respective User
s, it doesn't seem as simple as I thought. I still need to figure out how.
On the other hand, I still do not understand why using oasgraph as a module within the loopback project would prompt me to query for "users2" and "gameProfiles2" instead of "users" and "gameProfiles." For the time being, I am using the CLI method of calling npx oasgraph http://localhost:3000/openapi.json
as workaround since that doesn't cause the issue.
query for "users2" and "gameProfiles2" instead of "users" and "gameProfiles."
I think that is down to the oasgraph implementation. Probably prudent to raise the issue here: https://github.com/strongloop/oasgraph/issues
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS
file at the top-level of this repository. This issue will be closed within 30 days of being stale.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS
file at the top-level of this repository.
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:
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 :
Current Behavior
Starting the server and navigating to GraphiQL I ran into two issues :
Comment
Would anyone have any idea as to why this might be happening? Your help is appreciated!