Skip to content

Question: How to handle 1:n relationships ? #300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zto-sbenning opened this issue Feb 3, 2020 · 2 comments
Closed

Question: How to handle 1:n relationships ? #300

zto-sbenning opened this issue Feb 3, 2020 · 2 comments

Comments

@zto-sbenning
Copy link

Hello there .

Thank you for the awesome work here !

Bad english here, TL;DR: Is their some plan for supporting 1:n relationships in openapi-to-graphql in the futur ?

In regard of this part of the documentation

To create nested object types for arrays, you will need to keep the following in mind.

Continuing from the previous example, let's say that there is a third operation called GET /friends/{userId} which would return an array of users, specifically the friends of a particular user. Furthermore, let's say you wanted to run the following query, which would allow you to get all the employers of Alan's friends:

query {
  friends(userId: "Alan") {
    currentEmployerId
    employer {
      name
    }
  }
}

If this was like the previous case, you would simply define a link from GET /friends/{userId} to GET /employers/{employerId}. However, this is impossible because of the current specification. This is because this operation returns an array rather than an object and the current specification does not provide a way to access individual elements of an array.

Nevertheless, OpenAPI-to-GraphQL can still create a nested relationship. This is because OpenAPI-to-GraphQL reuses object types. If GET /friends/{userId} returns an array of User object types, then each of those users will take on the links defined in other operations that return User object types. In other words, because GET /friends/{userId} returns an array of User object types and GET /users/{userId}, which also returns a User object type, has a link to GET /employers/{employerId}, you will still be able to get all the employers of a user's friends because of the shared type.

I understand that because of OAI/OpenAPI-Specification#1327 and OAI/OpenAPI-Specification#1305, we cannot resolve 1:n nested relationships (with OAS Link object) in openapi-to-graphql.

Am I right here ? If no, can you please point me to a solution reference ?

Is their some plan for supporting this in openapi-to-graphql in the futur ?

Would it be a good approch to use an OAS extention object to define these relationships to openapi-to-graphql ? This extention (like a x-Links property on the OAS response object) would be like the OAS Link object, but it would use JSON Path (or another way) to parse the parameters values over JSON Pointer ?
Or would it be a better approch to add an extention object at the Schema object level to express those relationships?

Best regards,

@Alan-Cha
Copy link
Collaborator

Alan-Cha commented Feb 3, 2020

I believe this is a duplicate of #301. Please see my comment in the other issue. Closing for now!

@Alan-Cha Alan-Cha closed this as completed Feb 3, 2020
@zto-sbenning
Copy link
Author

Hello,

This is indeed a mistake from me. Sorry for the redundancy with issues/301.

Can you please delete this one, as I cannot do it by myself.

Best regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants