Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Validation] Allow differing directives.
Related GraphQL-js commit graphql/graphql-js@9b11df2
  • Loading branch information
syrusakbary committed Apr 9, 2016
commit 5a972032ea9551409e8fb8d98683933f8cf4d966
29 changes: 0 additions & 29 deletions graphql/core/validation/rules/overlapping_fields_can_be_merged.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ def find_conflict(self, response_name, field1, field2):
[ast2]
)

if not self.same_directives(ast1.directives, ast2.directives):
return (
(response_name, 'they have differing directives'),
[ast1],
[ast2]
)

selection_set1 = ast1.selection_set
selection_set2 = ast2.selection_set

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

return True

@classmethod
def same_directives(cls, directives1, directives2):
# Check to see if they are empty directives or nones. If they are, we can
# bail out early.
if not (directives1 or directives2):
return True

if len(directives1) != len(directives2):
return False

directives2_values_to_arg = {a.name.value: a for a in directives2}

for directive1 in directives1:
directive2 = directives2_values_to_arg.get(directive1.name.value)
if not directive2:
return False

if not cls.same_arguments(directive1.arguments, directive2.arguments):
return False

return True

def collect_field_asts_and_defs(self, parent_type, selection_set, visited_fragment_names=None, ast_and_defs=None):
if visited_fragment_names is None:
visited_fragment_names = set()
Expand Down
52 changes: 9 additions & 43 deletions tests/core_validation/test_overlapping_fields_can_be_merged.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ def test_different_directives_with_different_aliases():
''')


def test_different_skip_or_include_directives_accepted():
expect_passes_rule(OverlappingFieldsCanBeMerged, '''
fragment differentDirectivesWithDifferentAliases on Dog {
name @include(if: true)
name @include(if: false)
}
''')


def test_same_aliases_with_different_field_targets():
expect_fails_rule(OverlappingFieldsCanBeMerged, '''
fragment sameAliasesWithDifferentFieldTargets on Dog {
Expand Down Expand Up @@ -148,49 +157,6 @@ def test_allows_different_args_where_no_conflict_is_possible():
}
''')

def test_conflicting_directives():
expect_fails_rule(OverlappingFieldsCanBeMerged, '''
fragment conflictingDirectiveArgs on Dog {
name @include(if: true)
name @skip(if: false)
}
''', [
fields_conflict('name', 'they have differing directives', L(3, 9), L(4, 9))
], sort_list=False)


def test_conflicting_directive_args():
expect_fails_rule(OverlappingFieldsCanBeMerged, '''
fragment conflictingDirectiveArgs on Dog {
name @include(if: true)
name @include(if: false)
}
''', [
fields_conflict('name', 'they have differing directives', L(3, 9), L(4, 9))
], sort_list=False)


def test_conflicting_args_with_matching_directives():
expect_fails_rule(OverlappingFieldsCanBeMerged, '''
fragment conflictingArgsWithMatchingDirectiveArgs on Dog {
doesKnowCommand(dogCommand: SIT) @include(if: true)
doesKnowCommand(dogCommand: HEEL) @include(if: true)
}
''', [
fields_conflict('doesKnowCommand', 'they have differing arguments', L(3, 9), L(4, 9))
], sort_list=False)


def test_conflicting_directives_with_matching_args():
expect_fails_rule(OverlappingFieldsCanBeMerged, '''
fragment conflictingDirectiveArgsWithMatchingArgs on Dog {
doesKnowCommand(dogCommand: SIT) @include(if: true)
doesKnowCommand(dogCommand: SIT) @skip(if: false)
}
''', [
fields_conflict('doesKnowCommand', 'they have differing directives', L(3, 9), L(4, 9))
], sort_list=False)


def test_encounters_conflict_in_fragments():
expect_fails_rule(OverlappingFieldsCanBeMerged, '''
Expand Down