File: mutation_root.md

package info (click to toggle)
ruby-graphql 2.2.17-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,584 kB
  • sloc: ruby: 67,505; ansic: 1,753; yacc: 831; javascript: 331; makefile: 6
file content (44 lines) | stat: -rw-r--r-- 1,166 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
---
layout: guide
doc_stub: false
search: true
section: Mutations
title: Mutation Root
desc: The Mutation object is the entry point for mutation operations.
index: 0
---

GraphQL mutations all begin with the `mutation` keyword:

```graphql
mutation($accountNumber: ID!, $newBalance: Int!) {
# ^^^^ here
  setAccountBalance(accountNumber: $accountNumber, newBalance: $newBalance) {
    # ...
  }
}
```

Operations that begin with `mutation` get special treatment by the GraphQL runtime: root fields are guaranteed
to be executed sequentially. This way, the effect of a series of mutations is predictable.

Mutations are executed by a specific GraphQL object, `Mutation`. This object is defined like any other GraphQL object:

```ruby
class Types::Mutation < Types::BaseObject
  # ...
end
```

Then, it must be attached to your schema with the `mutation(...)` configuration:

```ruby
class Schema < GraphQL::Schema
  # ...
  mutation(Types::Mutation)
end
```

Now, whenever an incoming request uses the `mutation` keyword, it will go to `Mutation`.

See {% internal_link "Mutation Classes", "/mutations/mutation_classes" %} for some helpers to define mutation fields.