Sha256: 7a9cfd92f48e9a1e1fc5c78b3c4bc357432e8d73d058f352f65b9bbfe657fbae
Contents?: true
Size: 1.86 KB
Versions: 8
Compression:
Stored size: 1.86 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) } 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
8 entries across 8 versions & 1 rubygems