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

Mutations for nested resources #7

Open
xpepermint opened this issue Nov 6, 2015 · 1 comment
Open

Mutations for nested resources #7

xpepermint opened this issue Nov 6, 2015 · 1 comment

Comments

@xpepermint
Copy link

Hey. When I write my code I'm designing it not coding thus I have lots of questions :). Btw, I like your code style. How would you handle nested resources like /projects/:project_id/products/:id. All tutorials (not just yours) have mutations defined on the root mutation (no nesting). As I described here graphql/graphql-js#221 we could have nested resources the same way as we would do it in REST (nested query). I wonder if that logic is acceptable in graphql. I would like to see how others handle this case.

Example:

// PUT /projects/:project_id/products/:id
mutation {

  // example 1
  findProject(id: 1) { // make sure that the project exists and we can access it before mutating data
    updateProduct(id: 1, name: "Foo") { // the resolve function receives a valid `project` as the first arg
      id
    }
  } 

  // example 2
  updateProjectProduct(projectId: 10, name: "Product 1") {id}

  // example 3
  updateProjectProduct(projectId: 10, product: { name: "Product 1"}) {id}

}

Also, should the update or delete mutation return an object or null or {status: 'ok'} or else?

Thank you!

@JeffML
Copy link

JeffML commented May 13, 2018

In addition to input types, have mutator types? The idea is that if a mutator type is returned from a mutation requests, it is treated as an extension of the mutation request.

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