Skip to content

Commit 7619a20

Browse files
authored
Merge pull request #5275 from rmosolgo/2.3-fix-fields-will-merge
[2.3] Lookup the right field in FieldsWillMerge
2 parents f20c5c3 + 119360c commit 7619a20

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

lib/graphql/static_validation/rules/fields_will_merge.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def find_fields_and_fragments(selections, owner_type:, parents:, fields:, fragme
345345
fields << Field.new(node, definition, owner_type, parents)
346346
when GraphQL::Language::Nodes::InlineFragment
347347
fragment_type = node.type ? @types.type(node.type.name) : owner_type
348-
find_fields_and_fragments(node.selections, parents: [*parents, fragment_type], owner_type: owner_type, fields: fields, fragment_spreads: fragment_spreads) if fragment_type
348+
find_fields_and_fragments(node.selections, parents: [*parents, fragment_type], owner_type: fragment_type, fields: fields, fragment_spreads: fragment_spreads) if fragment_type
349349
when GraphQL::Language::Nodes::FragmentSpread
350350
fragment_spreads << FragmentSpread.new(node.name, parents)
351351
end

spec/graphql/static_validation/rules/fields_will_merge_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,4 +998,45 @@
998998
refute_match %r/\$arg12/, error_messages.first
999999
end
10001000
end
1001+
1002+
describe "duplicate aliases on a interface with inline fragment spread" do
1003+
class DuplicateAliasesSchema < GraphQL::Schema
1004+
module Node
1005+
include GraphQL::Schema::Interface
1006+
field :id, ID
1007+
1008+
def self.resolve_type(obj, ctx)
1009+
Repository
1010+
end
1011+
end
1012+
1013+
class Repository < GraphQL::Schema::Object
1014+
implements Node
1015+
field :name, String
1016+
field :id, ID
1017+
end
1018+
1019+
class Query < GraphQL::Schema::Object
1020+
field :node, Node, fallback_value: { name: "graphql-ruby", id: "abcdef" }
1021+
end
1022+
1023+
query(Query)
1024+
orphan_types(Repository)
1025+
end
1026+
1027+
it "returns an error" do
1028+
query_str = 'query {
1029+
node {
1030+
... on Repository {
1031+
info: name
1032+
info: id
1033+
}
1034+
}
1035+
}
1036+
'
1037+
1038+
res = DuplicateAliasesSchema.execute(query_str)
1039+
assert_equal ["Field 'info' has a field conflict: name or id?"], res["errors"].map { |e| e["message"] }
1040+
end
1041+
end
10011042
end

0 commit comments

Comments
 (0)