Skip to content
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

Support creating nested objects in single mutation #4

Open
sorenbs opened this issue May 25, 2016 · 1 comment
Open

Support creating nested objects in single mutation #4

sorenbs opened this issue May 25, 2016 · 1 comment

Comments

@sorenbs
Copy link
Contributor

sorenbs commented May 25, 2016

Currently to create an object and link it to another object you have to perform two mutations:

mutation {
  createCity(name: "Berlin", knownFor: "cool GraphQL people")
}
mutation {
  createUser(name: "carl", cityId: "cityId")
}

This is a common enough use case that we want to support it in a single mutation. The straight forward implementation would be:

mutation {
  createUser(name: "carl", city: {name: "Berlin", knownFor: "cool GraphQL people"})
}

We still need to support linking existing objects. We could support it by having the input type for city contain optional fields for all types on the City model including the id and do runtime checks to ensure that all required constraints are satisfied:

mutation {
  createUser(name: "carl", city: {id: "cityId"})
}

It would be better if we could encode in the type system that the shape of the city input field should be {id!} || {name!, knownFor}

@sorenbs
Copy link
Contributor Author

sorenbs commented May 25, 2016

See graphql/graphql-js#207

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

No branches or pull requests

1 participant