Sha256: c30c4bc74b29092645de4fcb7a7c6ca6683654fdee14d02eb9c781f44d35078a

Contents?: true

Size: 1.86 KB

Versions: 7

Compression:

Stored size: 1.86 KB

Contents

require 'spec_helper'

describe GraphQL::StaticValidation::VariableUsagesAreAllowed do
  let(:document) { GraphQL.parse('
    query getCheese(
        $goodInt: Int = 1,
        $okInt: Int!,
        $badInt: Int,
        $badStr: String!,
        $goodAnimals: [DairyAnimal!]!,
        $badAnimals: [DairyAnimal]!,
        $deepAnimals: [[DairyAnimal!]!]!,
    ) {
      goodCheese:   cheese(id: $goodInt)  { source }
      okCheese:     cheese(id: $okInt)    { source }
      badCheese:    cheese(id: $badInt)   { source }
      badStrCheese: cheese(id: $badStr)   { source }
      cheese(id: 1) {
        similarCheese(source: $goodAnimals)
        other: similarCheese(source: $badAnimals)
        tooDeep: similarCheese(source: $deepAnimals)
      }

      milk(id: 1) {
        flavors(limit: $okInt)
      }
    }
  ')}

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

  it "finds variables used as arguments but don't match the argument's type" do
    assert_equal(4, errors.length)
    expected = [
      {
        "message"=>"Nullability mismatch on variable $badInt and argument id (Int / Int!)",
        "locations"=>[{"line"=>13, "column"=>28}]
      },
      {
        "message"=>"Type mismatch on variable $badStr and argument id (String! / Int!)",
        "locations"=>[{"line"=>14, "column"=>28}]
      },
      {
        "message"=>"Nullability mismatch on variable $badAnimals and argument source ([DairyAnimal]! / [DairyAnimal!]!)",
        "locations"=>[{"line"=>17, "column"=>30}]
      },
      {
        "message"=>"List dimension mismatch on variable $deepAnimals and argument source ([[DairyAnimal!]!]! / [DairyAnimal!]!)",
        "locations"=>[{"line"=>18, "column"=>32}]
      }
    ]
    assert_equal(expected, errors)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
graphql-0.10.4 spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb
graphql-0.10.3 spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb
graphql-0.10.2 spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb
graphql-0.10.1 spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb
graphql-0.10.0 spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb
graphql-0.9.5 spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb
graphql-0.9.4 spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb