Sha256: 9356da8cad97241de50bbfd4e5923e4444f7b21036486d42504e3f48cc3d6cb2

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

require 'spec_helper'

describe GraphQL::StaticValidation::ArgumentLiteralsAreCompatible do
  let(:document) { GraphQL.parse(%|
    query getCheese {
      cheese(id: "aasdlkfj") { source }
      cheese(id: 1) { source @skip(if: {id: 1})}
      yakSource: searchDairy(product: [{source: YAK, fatContent: 1.1}]) { source }
      badSource: searchDairy(product: [{source: 1.1}]) { source }
    }

    fragment cheeseFields on Cheese {
      similarCheese(source: 4.5)
    }
  |)}

  let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::ArgumentLiteralsAreCompatible]) }
  let(:errors) { validator.validate(document) }

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

    query_root_error = {
      "message"=>"Argument id on Field 'cheese' has an invalid value",
      "locations"=>[{"line"=>3, "column"=>7}]
    }
    assert_includes(errors, query_root_error)

    directive_error = {
      "message"=>"Argument if on Directive 'skip' has an invalid value",
      "locations"=>[{"line"=>4, "column"=>31}]
    }
    assert_includes(errors, directive_error)

    input_object_error = {
      "message"=>"Argument product on Field 'searchDairy' has an invalid value",
      "locations"=>[{"line"=>6, "column"=>7}]
    }
    assert_includes(errors, input_object_error)

    fragment_error = {
      "message"=>"Argument source on Field 'similarCheese' has an invalid value",
      "locations"=>[{"line"=>10, "column"=>7}]
    }
    assert_includes(errors, fragment_error)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
graphql-0.10.3 spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb
graphql-0.10.2 spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb
graphql-0.10.1 spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb