Sha256: 0ad3ed5caab387cc3a7d67b7cebdcfe559774128afd39e256230285bc1694d5f

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 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(3, 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)

    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

2 entries across 2 versions & 1 rubygems

Version Path
graphql-0.9.5 spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb
graphql-0.9.4 spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb