Sha256: c2a517d4f3c066877ca90d096c8774fda43daa04dbc4e8d84346095d82c787bf

Contents?: true

Size: 1.25 KB

Versions: 15

Compression:

Stored size: 1.25 KB

Contents

require "spec_helper"

describe GraphQL::StaticValidation::DirectivesAreInValidLocations do
  let(:query_string) {"
    query getCheese @skip(if: true) {
      okCheese: cheese(id: 1) {
        id @skip(if: true),
        source
        ... on Cheese @skip(if: true) {
          flavor
        }
      }
    }

    fragment whatever on Cheese @skip(if: true) {
      id
    }
  "}

  let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::DirectivesAreInValidLocations]) }
  let(:query) { GraphQL::Query.new(DummySchema, query_string) }
  let(:errors) { validator.validate(query)[:errors] }

  describe "invalid directive locations" do
    it "makes errors for them" do
      expected = [
        {
          "message"=> "'@skip' can't be applied to queries (allowed: fields, fragment spreads, inline fragments)",
          "locations"=>[{"line"=>2, "column"=>21}],
          "path"=>["query getCheese"],
        },
        {
          "message"=>"'@skip' can't be applied to fragment definitions (allowed: fields, fragment spreads, inline fragments)",
          "locations"=>[{"line"=>12, "column"=>33}],
           "path"=>["fragment whatever"],
        },
      ]
      assert_equal(expected, errors)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
graphql-0.18.14 spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb
graphql-0.18.13 spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb
graphql-0.18.12 spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb
graphql-0.18.11 spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb
graphql-0.18.10 spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb
graphql-0.18.9 spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb
graphql-0.18.8 spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb
graphql-0.18.7 spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb
graphql-0.18.6 spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb
graphql-0.18.5 spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb
graphql-0.18.4 spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb
graphql-0.18.3 spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb
graphql-0.18.2 spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb
graphql-0.18.1 spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb
graphql-0.18.0 spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb