Sha256: c5b5a381191a46a5922403cd732ed201c316ca888f100bd63f80b6771b2a0aaa

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

require "spec_helper"

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

  let(:schema) {
    query_root = GraphQL::Field.define do
      name "Query"
      description "Query root of the system"
    end

    GraphQL::Schema.define do
      query query_root
    end
  }

  let(:validator) { GraphQL::StaticValidation::Validator.new(schema: schema, rules: [GraphQL::StaticValidation::MutationRootExists]) }
  let(:query) { GraphQL::Query.new(schema, query_string) }
  let(:errors) { validator.validate(query)[:errors] }

  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"],
    }
    assert_includes(errors, missing_mutation_root_error)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
graphql-0.18.14 spec/graphql/static_validation/rules/mutation_root_exists_spec.rb
graphql-0.18.13 spec/graphql/static_validation/rules/mutation_root_exists_spec.rb
graphql-0.18.12 spec/graphql/static_validation/rules/mutation_root_exists_spec.rb