Sha256: c41413b9156d46145fea7b3201fd959006b8df92da30d0947494b04ab19ae46b

Contents?: true

Size: 1.63 KB

Versions: 75

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true
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

75 entries across 75 versions & 1 rubygems

Version Path
graphql-1.8.18 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.17 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.16 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.15 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.14 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.13 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.12 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.11 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.10 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.9 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.8 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.7 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.6 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.5 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.4 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.3 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.2 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.1 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.0 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb
graphql-1.8.0.pre11 spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb