Sha256: b31ad60a3bb8c04320f99bb2000cf62c26e2ae14ad6e0cc23933df9ac30598a2

Contents?: true

Size: 1.87 KB

Versions: 19

Compression:

Stored size: 1.87 KB

Contents

require "spec_helper"

describe GraphQL::StaticValidation::FieldsWillMerge do
  let(:query_string) {"
    query getCheese($sourceVar: DairyAnimal!) {
      cheese(id: 1) {
        id,
        nickname: name,
        nickname: fatContent,
        fatContent
        differentLevel: fatContent
        similarCheese(source: $sourceVar)

        similarCow: similarCheese(source: COW) {
          similarCowSource: source,
          differentLevel: fatContent
        }
        ...cheeseFields
        ... on Cheese {
          fatContent: name
          similarCheese(source: SHEEP)
        }
      }
    }
    fragment cheeseFields on Cheese {
      fatContent,
      similarCow: similarCheese(source: COW) { similarCowSource: id, id }
      id @someFlag
    }
  "}

  let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::FieldsWillMerge]) }
  let(:query) { GraphQL::Query.new(DummySchema, query_string) }
  let(:errors) { validator.validate(query)[:errors] }
  let(:error_messages) { errors.map { |e| e["message" ] }}

  it "finds field naming conflicts" do
    expected_errors = [
      "Field 'id' has a directive conflict: [] or [someFlag]?",                 # different directives
      "Field 'id' has a directive argument conflict: [] or [{}]?",              # not sure this is a great way to handle it but here we are!
      "Field 'nickname' has a field conflict: name or fatContent?",             # alias conflict in query
      "Field 'fatContent' has a field conflict: fatContent or name?",           # alias/name conflict in query and fragment
      "Field 'similarCheese' has an argument conflict: {\"source\":\"sourceVar\"} or {\"source\":\"SHEEP\"}?", # different arguments
      "Field 'similarCowSource' has a field conflict: source or id?",           # nested conflict
    ]
    assert_equal(expected_errors, error_messages)
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
graphql-0.18.13 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.18.12 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.18.11 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.18.10 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.18.9 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.18.8 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.18.7 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.18.6 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.18.5 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.18.4 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.18.3 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.18.2 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.18.1 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.18.0 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.17.2 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.17.1 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.17.0 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.16.1 spec/graphql/static_validation/rules/fields_will_merge_spec.rb
graphql-0.16.0 spec/graphql/static_validation/rules/fields_will_merge_spec.rb