Skip to content

Commit 5a97203

Browse files
committed
[Validation] Allow differing directives.
Related GraphQL-js commit graphql/graphql-js@9b11df2
1 parent a6424ab commit 5a97203

File tree

2 files changed

+9
-72
lines changed

2 files changed

+9
-72
lines changed

graphql/core/validation/rules/overlapping_fields_can_be_merged.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,6 @@ def find_conflict(self, response_name, field1, field2):
8888
[ast2]
8989
)
9090

91-
if not self.same_directives(ast1.directives, ast2.directives):
92-
return (
93-
(response_name, 'they have differing directives'),
94-
[ast1],
95-
[ast2]
96-
)
97-
9891
selection_set1 = ast1.selection_set
9992
selection_set2 = ast2.selection_set
10093

@@ -165,28 +158,6 @@ def same_arguments(cls, arguments1, arguments2):
165158

166159
return True
167160

168-
@classmethod
169-
def same_directives(cls, directives1, directives2):
170-
# Check to see if they are empty directives or nones. If they are, we can
171-
# bail out early.
172-
if not (directives1 or directives2):
173-
return True
174-
175-
if len(directives1) != len(directives2):
176-
return False
177-
178-
directives2_values_to_arg = {a.name.value: a for a in directives2}
179-
180-
for directive1 in directives1:
181-
directive2 = directives2_values_to_arg.get(directive1.name.value)
182-
if not directive2:
183-
return False
184-
185-
if not cls.same_arguments(directive1.arguments, directive2.arguments):
186-
return False
187-
188-
return True
189-
190161
def collect_field_asts_and_defs(self, parent_type, selection_set, visited_fragment_names=None, ast_and_defs=None):
191162
if visited_fragment_names is None:
192163
visited_fragment_names = set()

tests/core_validation/test_overlapping_fields_can_be_merged.py

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ def test_different_directives_with_different_aliases():
6868
''')
6969

7070

71+
def test_different_skip_or_include_directives_accepted():
72+
expect_passes_rule(OverlappingFieldsCanBeMerged, '''
73+
fragment differentDirectivesWithDifferentAliases on Dog {
74+
name @include(if: true)
75+
name @include(if: false)
76+
}
77+
''')
78+
79+
7180
def test_same_aliases_with_different_field_targets():
7281
expect_fails_rule(OverlappingFieldsCanBeMerged, '''
7382
fragment sameAliasesWithDifferentFieldTargets on Dog {
@@ -148,49 +157,6 @@ def test_allows_different_args_where_no_conflict_is_possible():
148157
}
149158
''')
150159

151-
def test_conflicting_directives():
152-
expect_fails_rule(OverlappingFieldsCanBeMerged, '''
153-
fragment conflictingDirectiveArgs on Dog {
154-
name @include(if: true)
155-
name @skip(if: false)
156-
}
157-
''', [
158-
fields_conflict('name', 'they have differing directives', L(3, 9), L(4, 9))
159-
], sort_list=False)
160-
161-
162-
def test_conflicting_directive_args():
163-
expect_fails_rule(OverlappingFieldsCanBeMerged, '''
164-
fragment conflictingDirectiveArgs on Dog {
165-
name @include(if: true)
166-
name @include(if: false)
167-
}
168-
''', [
169-
fields_conflict('name', 'they have differing directives', L(3, 9), L(4, 9))
170-
], sort_list=False)
171-
172-
173-
def test_conflicting_args_with_matching_directives():
174-
expect_fails_rule(OverlappingFieldsCanBeMerged, '''
175-
fragment conflictingArgsWithMatchingDirectiveArgs on Dog {
176-
doesKnowCommand(dogCommand: SIT) @include(if: true)
177-
doesKnowCommand(dogCommand: HEEL) @include(if: true)
178-
}
179-
''', [
180-
fields_conflict('doesKnowCommand', 'they have differing arguments', L(3, 9), L(4, 9))
181-
], sort_list=False)
182-
183-
184-
def test_conflicting_directives_with_matching_args():
185-
expect_fails_rule(OverlappingFieldsCanBeMerged, '''
186-
fragment conflictingDirectiveArgsWithMatchingArgs on Dog {
187-
doesKnowCommand(dogCommand: SIT) @include(if: true)
188-
doesKnowCommand(dogCommand: SIT) @skip(if: false)
189-
}
190-
''', [
191-
fields_conflict('doesKnowCommand', 'they have differing directives', L(3, 9), L(4, 9))
192-
], sort_list=False)
193-
194160

195161
def test_encounters_conflict_in_fragments():
196162
expect_fails_rule(OverlappingFieldsCanBeMerged, '''

0 commit comments

Comments
 (0)