Skip to content

Writing tests for mutations

John Bachir edited this page Jul 7, 2019 · 1 revision

Here's one possible pattern, this discussion:

# spec/graph/mutations/do_thing_spec.rb

query =
  <<~GQL
    mutation doThing(
      $foo: String
      $bar: String
      ...
  GQL

result = Schema.execute query, variables: { 'foo' => foo, 'bar' => bar }

data = result.to_h['data']['doThing']['widget']

expect(data).to include(
  'id' => 1,
  'value' => bloop,
  'stuff' => { 'name' => name,
                'id' => 2}
)