Sha256: 2668191ff6551f06b3594608faeeabec1adc5869f1e6355a661ef7f2e941aada

Contents?: true

Size: 1.6 KB

Versions: 14

Compression:

Stored size: 1.6 KB

Contents

require "spec_helper"

describe GraphQL::StaticValidation::VariablesAreUsedAndDefined do
  include StaticValidationHelpers

  let(:query_string) {'
    query getCheese(
      $usedVar: Int!,
      $usedInnerVar: [DairyAnimal!]!,
      $usedInlineFragmentVar: Int!,
      $usedFragmentVar: Int!,
      $notUsedVar: Int!,
    ) {
      c1: cheese(id: $usedVar) {
        __typename
      }
      ... on Query {
        c2: cheese(id: $usedInlineFragmentVar) {
          similarCheese(source: $usedInnerVar) { __typename }
        }

      }

      c3: cheese(id: $undefinedVar) { __typename }

      ... outerCheeseFields
    }

    fragment outerCheeseFields on Query {
      ... innerCheeseFields
    }

    fragment innerCheeseFields on Query {
      c4: cheese(id: $undefinedFragmentVar) { __typename }
      c5: cheese(id: $usedFragmentVar) { __typename }
    }
  '}

  it "finds variables which are used-but-not-defined or defined-but-not-used" do
    expected = [
      {
        "message"=>"Variable $notUsedVar is declared by getCheese but not used",
        "locations"=>[{"line"=>2, "column"=>5}],
        "fields"=>["query getCheese"],
      },
      {
        "message"=>"Variable $undefinedVar is used by getCheese but not declared",
        "locations"=>[{"line"=>19, "column"=>22}],
        "fields"=>["query getCheese", "c3", "id"],
      },
      {
        "message"=>"Variable $undefinedFragmentVar is used by innerCheeseFields but not declared",
        "locations"=>[{"line"=>29, "column"=>22}],
        "fields"=>["fragment innerCheeseFields", "c4", "id"],
      },
    ]

    assert_equal(expected, errors)
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
graphql-1.2.6 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.2.5 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.2.4 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.2.3 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.2.2 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.2.1 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.2.0 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.1.0 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.0.0 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-0.19.4 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-0.19.3 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-0.19.2 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-0.19.1 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-0.19.0 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb