File: mutation_root_exists_spec.rb

package info (click to toggle)
ruby-graphql 2.5.19-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,868 kB
  • sloc: ruby: 80,420; ansic: 1,808; yacc: 845; javascript: 480; makefile: 6
file content (38 lines) | stat: -rw-r--r-- 961 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
# frozen_string_literal: true
require "spec_helper"

describe GraphQL::StaticValidation::MutationRootExists do
  include StaticValidationHelpers

  let(:query_string) {%|
    mutation addBagel {
      introduceShip(input: {shipName: "Bagel"}) {
        clientMutationId
        shipEdge {
          node { name, id }
        }
      }
    }
  |}

  let(:schema) {
    Class.new(GraphQL::Schema) do
      query_root = Class.new(GraphQL::Schema::Object) do
        graphql_name "Query"
      end

      query query_root
    end
  }

  it "errors when a mutation is performed on a schema without a mutation root" do
    assert_equal(1, errors.length)
    missing_mutation_root_error = {
      "message"=>"Schema is not configured for mutations",
      "locations"=>[{"line"=>2, "column"=>5}],
      "path"=>["mutation addBagel"],
      "extensions"=>{"code"=>"missingMutationConfiguration"}
    }
    assert_includes(errors, missing_mutation_root_error)
  end
end