question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New "many" mutations: `updatePosts` / `createPosts`

See original GitHub issue

Currently we have these:

Singular Many
createPost
Post allPosts
updatePost
deletePost deletePosts

The missing mutations would be createPosts & updatePosts to complete that table.

The input parameters would be the same for the Many case as for the Singular case, but as an Array (and likewise for the return type):

input PostsUpdateInput {
  id: ID!
  data: PostUpdateInput
}

input PostsCreateInput {
  data: PostCreateInput
}

type Mutation {
  updatePosts(data: [PostsUpdateInput]): Posts
  createPosts(data: [PostsCreateInput]): Posts
}

Which you’d then execute like so:

mutation {
  createPosts(data: [
    { data: { title: "Hello" } },
    { data: { title: "A post" } }
  ]) {
    id
    title
  }
}
mutation {
  updatePosts(data: [
    { id: "abc123", data: { title: "Hello" } },
    { id: "def456", data: { title: "A post" } }
  ]) {
    id
    title
  }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
timlesliecommented, Dec 10, 2018

I’m +1 on this idea. I think the deleteMutation and deleteManyMutation methods on the List class give us the pattern for how to implement these mutations.

At the moment the deletePosts mutation runs each of the delete operations independently, so even if one fails for some reason (e.g. validation), the others still get deleted. This is by design and is believed to be correct.

0reactions
maheraldouscommented, Aug 31, 2020

I just started using Keystone and when I use this code below in the image, it work and create one user but as long I use the second code it won’t work

https://prnt.sc/u97b18

https://prnt.sc/u97bmq

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL Mutations | Contember
Contember offers advanced mutations for data modification. ... createPost(data: PostCreateInput!) ... Using a create mutation you can create new records.
Read more >
Using nested mutations - GraphQL API for WordPress
The query below executes a standard mutation, using the mutation field updatePost from the root type: mutation { updatePost(id: 5, title: "New title")...
Read more >
Nested Mutations - Lighthouse PHP
Nested Mutations. Lighthouse allows you to create, update or delete models and their associated relationships, all in one single mutation.
Read more >
Using GraphQL with Python – A Complete Guide
To do so we will follow the same pattern. First, we will update the schema and add a new mutation called updatePost ....
Read more >
Supporting opt-in nested mutations in GraphQL
mutation { updatePost(id: 5, title: "New title") { title } } ... the mutation fields ( createPost and updatePost ) can only appear...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found