Skip to content

Instantly share code, notes, and snippets.

@coco98
Last active March 13, 2019 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coco98/9d82133e4d760c1d8c8466e9c13bf094 to your computer and use it in GitHub Desktop.
Save coco98/9d82133e4d760c1d8c8466e9c13bf094 to your computer and use it in GitHub Desktop.
single mutation to update relationships
#Without query variables
mutation updateChildren {
delete_children(where: {parent_id: {_eq: 1}}) {
affected_rows
}
insert_children(objects: [{name: "child1", parent_id: 1}, {name: "child2", parent_id: 1}]) {
affected_rows
}
}
#######################################################
#With query variables
mutation updateChildrenWithQueryVars ($parentId: Int!, $newChildren: [insert_children_input!]!) {
delete_children(where: {parent_id: {_eq: $parentId}}) {
affected_rows
}
insert_children(objects: $newChildren) {
affected_rows
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment