Sha256: 9ca77b3fdfb31df3725dd71000dd142f0ef4bb832cc03d7725b16790cef3f997

Contents?: true

Size: 1.75 KB

Versions: 9

Compression:

Stored size: 1.75 KB

Contents

require "spec_helper"

describe GraphQL::StaticValidation::ArgumentsAreDefined do
  include StaticValidationHelpers

  let(:query_string) {"
    query getCheese {
      okCheese: cheese(id: 1) { source }
      cheese(silly: false, id: 2) { source }
      searchDairy(product: [{wacky: 1}]) { ...cheeseFields }
    }

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

  it "finds undefined arguments to fields and directives" do
    # There's an extra error here, the unexpected argument on "DairyProductInput"
    # triggers _another_ error that the field expected a different type
    assert_equal(5, errors.length)

    query_root_error = {
      "message"=>"Field 'cheese' doesn't accept argument 'silly'",
      "locations"=>[{"line"=>4, "column"=>7}],
      "fields"=>["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}],
      "fields"=>["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}],
      "fields"=>["fragment cheeseFields", "similarCheese", "nonsense"],
    }
    assert_includes(errors, fragment_error)

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
graphql-1.2.1 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-1.2.0 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-1.1.0 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-1.0.0 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.19.4 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.19.3 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.19.2 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.19.1 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb
graphql-0.19.0 spec/graphql/static_validation/rules/arguments_are_defined_spec.rb