Sha256: 527d2ad86a269f851f9bcc1dc441259079195a9b3ae35aefdc221cd60064ef12

Contents?: true

Size: 1.28 KB

Versions: 11

Compression:

Stored size: 1.28 KB

Contents

require 'spec_helper'

describe GraphQL::StaticValidation::VariablesAreUsedAndDefined do
  let(:document) { GraphQL.parse('
    query getCheese($id: Int, $str: String, $notUsedVar: Float, $bool: Boolean) {
      cheese(id: $id) {
        source(str: $str)
        whatever(undefined: $undefinedVar)
        ... on Cheese {
          something(bool: $bool)
        }
      }
    }

    fragment outerCheeseFields on Cheese {
      ... innerCheeseFields
    }

    fragment innerCheeseFields on Cheese {
      source(notDefined: $notDefinedVar)
    }
  ')}

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

  it "finds variables which are used-but-not-defined or defined-but-not-used" do
    expected = [
      {
        "message"=>"Variable $undefinedVar is used but not declared",
        "locations"=>[{"line"=>5, "column"=>30}]
      },
      {
        "message"=>"Variable $notUsedVar is declared but not used",
        "locations"=>[{"line"=>2, "column"=>5}]
      },
      {
        "message"=>"Variable $notDefinedVar is used but not declared",
        "locations"=>[{"line"=>17, "column"=>27}]
      },
    ]
    assert_equal(expected, errors)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
graphql-0.9.2 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-0.8.1 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-0.8.0 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-0.7.1 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-0.7.0 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-0.6.2 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-0.6.1 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-0.6.0 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-0.5.0 spec/graph_ql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-0.4.0 spec/graph_ql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-0.3.0 spec/graph_ql/static_validation/rules/variables_are_used_and_defined_spec.rb