-
-
Notifications
You must be signed in to change notification settings - Fork 895
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
[GraphQL] One-to-Many relations? #1964
Comments
It was possible before, but was removed because it was causing some issues with the introspection. |
I see... so it seems like this feature won't be returning until Facebook agrees on the spec for it. @alanpoulain Until the spec is agreed upon, what is the recommended approach to working with one-to-many data structures? |
Yes or if the schema builder generates two fields. One for the IRI and the other for the data. |
I made it work like this #3422 |
I think having two fields is not the best solution in every case. This becomes an issue when a field may not be null. The client would then have to fill both fields which does not make sense. Alternatively both fields are nullable which makes it harder to interpret the schema and would allow invalid input data that "looks right". How about adding a temporary, user generated id that can be used to identify an object after it has been created? When the client adds such a temporary id to a create mutation and uses the same id as a reference later in the same request it would refer to the newly created entity. mutation {
createFoo(input: { tmpId: "myAwesomeObject", name: "test" }) {
foo {
id
name
}
}
createBar(input: { foo: "myAwesomeObject", name: "test2" }) {
bar {
id
name
foo {
id
name
}
}
}
}
would return something like: {
"createFoo": {
"foo": {
"id": "/api/foo/1",
"name": "test"
}
},
"createBar": {
"bar": {
"id": "/api/bar/1",
"name": "test2",
"foo": {
"id": "/api/foo/1",
"name": "test"
}
}
}
} The temporary id can be stored throughout the request, along with the entity class name and the newly persisted entity. |
See https://api-platform.com/docs/main/core/graphql/#embedded-relation-input-creation-of-relation-in-mutation for a way to solve this issue. |
When defining a one-to-many relation (ex. User->Vehicles), GraphQL currently expects
[String]
on the create/update mutation. Is there a way to create new Vehicles in the same request as creating/updating the User? It seems like GraphQL expects you to pass a list of Vehicle IDs instead of an array of Vehicle data like I would do in a REST call.I would like to avoid doing multiple API calls if possible. Any ideas on how to accomplish this?
The text was updated successfully, but these errors were encountered: