Sha256: d6f578ca939c0bd32f71b52f0240aea3366b556c88fc7ccb66aa19bbd551a623

Contents?: true

Size: 1.75 KB

Versions: 15

Compression:

Stored size: 1.75 KB

Contents

require "spec_helper"

describe GraphQL::StaticValidation::ArgumentsAreDefined do
  let(:query_string) {"
    query getCheese {
      cheese(id: 1) { source }
      cheese(silly: false) { source }
      searchDairy(product: [{wacky: 1}])
    }

    fragment cheeseFields on Cheese {
      similarCheese(source: SHEEP, nonsense: 1)
      id @skip(something: 3.4)
    }
  "}

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

  it "finds undefined arguments to fields and directives" do
    assert_equal(4, errors.length)

    query_root_error = {
      "message"=>"Field 'cheese' doesn't accept argument 'silly'",
      "locations"=>[{"line"=>4, "column"=>7}],
      "path"=>["query getCheese", "cheese", "silly"],
    }
    assert_includes(errors, query_root_error)

    input_obj_record = {
      "message"=>"InputObject 'DairyProductInput' doesn't accept argument 'wacky'",
      "locations"=>[{"line"=>5, "column"=>29}],
      "path"=>["query getCheese", "searchDairy", "product", "wacky"],
    }
    assert_includes(errors, input_obj_record)

    fragment_error = {
      "message"=>"Field 'similarCheese' doesn't accept argument 'nonsense'",
      "locations"=>[{"line"=>9, "column"=>7}],
      "path"=>["fragment cheeseFields", "similarCheese", "nonsense"],
    }
    assert_includes(errors, fragment_error)

    directive_error = {
      "message"=>"Directive 'skip' doesn't accept argument 'something'",
      "locations"=>[{"line"=>10, "column"=>10}],
      "path"=>["fragment cheeseFields", "id", "something"],
    }
    assert_includes(errors, directive_error)
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
graphql-0.18.14 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.18.13 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.18.12 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.18.11 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.18.10 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.18.9 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.18.8 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.18.7 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.18.6 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.18.5 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.18.4 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.18.3 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.18.2 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.18.1 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.18.0 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb