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