def test_different_object_into_object_in_inline_fragment(): expect_fails_rule( PossibleFragmentSpreads, ''' fragment invalidObjectWithinObjectAnon on Cat { ... on Dog { barkVolume } } ''', [error_anon('Cat', 'Dog', 3, 9)])
def test_unknown_args_amongst_known_args(): expect_fails_rule(KnownArgumentNames, ''' fragment oneGoodArgOneInvalidArg on Dog { doesKnowCommand(whoknows: 1, dogCommand: SIT, unknown: true) } ''', [unknown_arg('whoknows', 'doesKnowCommand', 'Dog', 3, 25), unknown_arg('unknown', 'doesKnowCommand', 'Dog', 3, 55)])
def test_no_spreading_itself_deeply(): expect_fails_rule( NoFragmentCycles, ''' fragment fragA on Dog { ...fragB } fragment fragB on Dog { ...fragC } fragment fragC on Dog { ...fragO } fragment fragX on Dog { ...fragY } fragment fragY on Dog { ...fragZ } fragment fragZ on Dog { ...fragO } fragment fragO on Dog { ...fragP } fragment fragP on Dog { ...fragA, ...fragX } ''', [ cycle_error_message( 'fragA', [ 'fragB', 'fragC', 'fragO', 'fragP'], L( 2, 29), L( 3, 29), L( 4, 29), L( 8, 29), L( 9, 29)), cycle_error_message( 'fragO', [ 'fragP', 'fragX', 'fragY', 'fragZ'], L( 8, 29), L( 9, 39), L( 5, 29), L( 6, 29), L( 7, 29))])
def test_scalar_selection_not_allowed_with_directives(): expect_fails_rule( ScalarLeafs, ''' fragment scalarSelectionsNotAllowedWithDirectives on Dog { name @include(if: true) { isAlsoHumanName } } ''', [no_scalar_subselection('name', 'String', 3, 33)])
def test_scalar_selection_not_allowed_with_directives_and_args(): expect_fails_rule( ScalarLeafs, ''' fragment scalarSelectionsNotAllowedWithDirectivesAndArgs on Dog { doesKnowCommand(dogCommand: SIT) @include(if: true) { sinceWhen } } ''', [no_scalar_subselection('doesKnowCommand', 'Boolean', 3, 61)])
def test_scalar_selection_not_allowed_on_enum(): expect_fails_rule( ScalarLeafs, ''' fragment scalarSelectionsNotAllowedOnEnum on Cat { furColor { inHexdec } } ''', [no_scalar_subselection('furColor', 'FurColor', 3, 18)])
def test_scalar_selection_not_allowed_with_args(): expect_fails_rule( ScalarLeafs, ''' fragment scalarSelectionsNotAllowedWithArgs on Dog { doesKnowCommand(dogCommand: SIT) { sinceWhen } } ''', [no_scalar_subselection('doesKnowCommand', 'Boolean', 3, 42)])
def test_object_type_missing_selection(): expect_fails_rule( ScalarLeafs, ''' query directQueryOnObjectWithoutSubFields { human } ''', [missing_obj_subselection('human', 'Human', 3, 9)])
def test_scalar_selection_not_allowed_on_boolean(): expect_fails_rule( ScalarLeafs, ''' fragment scalarSelectionsNotAllowedOnBoolean on Dog { barks { sinceWhen } } ''', [no_scalar_subselection('barks', 'Boolean', 3, 15)])
def test_with_misplaced_directives(): expect_fails_rule(KnownDirectives, ''' query Foo @include(if: true) { name ...Frag } ''', [misplaced_directive('include', 'operation', 2, 17)])
def test_duplicate_field_arguments(): expect_fails_rule( UniqueArgumentNames, ''' { field(arg1: "value", arg1: "value") } ''', [duplicate_arg('arg1', 3, 13, 3, 28)])
def test_duplicate_directive_arguments(): expect_fails_rule( UniqueArgumentNames, ''' { field @directive(arg1: "value", arg1: "value") } ''', [duplicate_arg('arg1', 3, 24, 3, 39)])
def test_interface_into_non_overlapping_interface_in_inline_fragment(): expect_fails_rule( PossibleFragmentSpreads, ''' fragment invalidInterfaceWithinInterfaceAnon on Pet { ...on Intelligent { iq } } ''', [error_anon('Pet', 'Intelligent', 3, 9)])
def test_input_object_is_invalid_fragment_type(): expect_fails_rule( FragmentsOnCompositeTypes, ''' fragment inputFragment on ComplexInput { stringField } ''', [error('inputFragment', 'ComplexInput', 2, 33)])
def test_reports_each_conflict_once(): expect_fails_rule(OverlappingFieldsCanBeMerged, ''' { f1 { ...A ...B } f2 { ...B ...A } f3 { ...A ...B x: c } } fragment A on Type { x: a } fragment B on Type { x: b } ''', [ fields_conflict('x', 'a and b are different fields', L(18, 9), L(21, 9)), fields_conflict('x', 'a and c are different fields', L(18, 9), L(14, 13)), fields_conflict('x', 'b and c are different fields', L(21, 9), L(14, 13)) ], sort_list=False)
def test_contains_unknown_fragments_with_ref_cycle(): expect_fails_rule( NoUnusedFragments, ''' query Foo { human(id: 4) { ...HumanFields1 } } query Bar { human(id: 4) { ...HumanFields2 } } fragment HumanFields1 on Human { name ...HumanFields3 } fragment HumanFields2 on Human { name } fragment HumanFields3 on Human { name } fragment Unused1 on Human { name ...Unused2 } fragment Unused2 on Human { name ...Unused1 } ''', [ unused_fragment('Unused1', 22, 7), unused_fragment('Unused2', 26, 7), ])
def test_invalid_arg_name(): expect_fails_rule( KnownArgumentNames, ''' fragment invalidArgName on Dog { doesKnowCommand(unknown: true) } ''', [unknown_arg('unknown', 'doesKnowCommand', 'Dog', 3, 25)])
def test_duplicate_directive_arguments(): expect_fails_rule(UniqueArgumentNames, ''' { field @directive(arg1: "value", arg1: "value") } ''', [duplicate_arg('arg1', 3, 24, 3, 39)] )
def test_contains_unknown_fragments_with_ref_cycle(): expect_fails_rule(NoUnusedFragments, ''' query Foo { human(id: 4) { ...HumanFields1 } } query Bar { human(id: 4) { ...HumanFields2 } } fragment HumanFields1 on Human { name ...HumanFields3 } fragment HumanFields2 on Human { name } fragment HumanFields3 on Human { name } fragment Unused1 on Human { name ...Unused2 } fragment Unused2 on Human { name ...Unused1 } ''', [ unused_fragment('Unused1', 22, 7), unused_fragment('Unused2', 26, 7), ])
def test_interface_into_non_overlapping_interface(): expect_fails_rule(PossibleFragmentSpreads, ''' fragment invalidInterfaceWithinInterface on Pet { ...intelligentFragment } fragment intelligentFragment on Intelligent { iq } ''', [error('intelligentFragment', 'Pet', 'Intelligent', 3, 9)])
def test_scalar_is_invalid_fragment_type(): expect_fails_rule( FragmentsOnCompositeTypes, ''' fragment scalarFragment on Boolean { bad } ''', [error('scalarFragment', 'Boolean', 2, 34)])
def test_variable_not_defined(): expect_fails_rule( NoUndefinedVariables, ''' query Foo($a: String, $b: String, $c: String) { field(a: $a, b: $b, c: $c, d: $d) } ''', [undefined_var('d', 3, 39)])
def test_multiple_undefined_variables_produce_multiple_errors(): expect_fails_rule( NoUndefinedVariables, ''' query Foo($b: String) { ...FragAB } query Bar($a: String) { ...FragAB } fragment FragAB on Type { field1(a: $a, b: $b) ...FragC field3(a: $a, b: $b) } fragment FragC on Type { field2(c: $c) } ''', [ undefined_var_by_op('a', 9, 19, 'Foo', 2, 7), undefined_var_by_op('c', 14, 19, 'Foo', 2, 7), undefined_var_by_op('a', 11, 19, 'Foo', 2, 7), undefined_var_by_op('b', 9, 26, 'Bar', 5, 7), undefined_var_by_op('c', 14, 19, 'Bar', 5, 7), undefined_var_by_op('b', 11, 26, 'Bar', 5, 7), ])
def test_list_variables_with_invalid_item(): expect_fails_rule( DefaultValuesOfCorrectType, ''' query invalidItem($a: [String] = ["one", 2]) { dog { name } } ''', [bad_value('a', '[String]', '["one", 2]', 2, 38)])
def test_variables_missing_required_field(): expect_fails_rule( DefaultValuesOfCorrectType, ''' query MissingRequiredField($a: ComplexInput = {intField: 3}) { dog { name } } ''', [bad_value('a', 'ComplexInput', '{intField: 3}', 2, 51)])
def test_no_spreading_itself_indirectly_reports_opposite_order(): expect_fails_rule(NoFragmentCycles, ''' fragment fragB on Dog { ...fragA } fragment fragA on Dog { ...fragB } ''', [ cycle_error_message('fragB', ['fragA'], L(2, 29), L(3, 29)) ])
def test_enum_is_invalid_fragment_type(): expect_fails_rule( FragmentsOnCompositeTypes, ''' fragment scalarFragment on FurColor { bad } ''', [error('scalarFragment', 'FurColor', 2, 34)])
def test_duplicate_input_object_fields(): expect_fails_rule( UniqueInputFieldNames, ''' { field(arg: { f1: "value", f1: "value" }) } ''', [duplicate_field("f1", L(3, 22), L(3, 35))])
def test_defined_on_implementors_queried_on_union(): expect_fails_rule( FieldsOnCorrectType, ''' fragment definedOnImplementorsQueriedOnUnion on CatOrDog { name } ''', [undefined_field('name', 'CatOrDog', 3, 9)])
def test_field_not_defined_on_fragment(): expect_fails_rule( FieldsOnCorrectType, ''' fragment fieldNotDefined on Dog { meowVolume } ''', [undefined_field('meowVolume', 'Dog', 3, 9)])
def test_defined_on_implementors_but_not_on_interface(): expect_fails_rule( FieldsOnCorrectType, ''' fragment definedOnImplementorsButNotInterface on Pet { nickname } ''', [undefined_field('nickname', 'Pet', 3, 9)])
def test_direct_field_selection_on_union(): expect_fails_rule( FieldsOnCorrectType, ''' fragment directFieldSelectionOnUnion on CatOrDog { directField } ''', [undefined_field('directField', 'CatOrDog', 3, 9)])
def test_aliased_lying_field_target_not_defined(): expect_fails_rule( FieldsOnCorrectType, ''' fragment aliasedLyingFieldTargetNotDefined on Dog { barkVolume : kawVolume } ''', [undefined_field('kawVolume', 'Dog', 3, 9)])
def test_not_defined_on_interface(): expect_fails_rule( FieldsOnCorrectType, ''' fragment notDefinedOnInterface on Pet { tailLength } ''', [undefined_field('tailLength', 'Pet', 3, 9)])
def test_duplicate_field_arguments(): expect_fails_rule(UniqueArgumentNames, ''' { field(arg1: "value", arg1: "value") } ''', [duplicate_arg('arg1', 3, 13, 3, 28)] )
def test_undirective_args_are_invalid(): expect_fails_rule( KnownArgumentNames, ''' { dog @skip(unless: true) } ''', [unknown_directive_arg('unless', 'skip', 3, 19)])
def test_variable_not_used(): expect_fails_rule( NoUnusedVariables, ''' query Foo($a: String, $b: String, $c: String) { field(a: $a, b: $b) } ''', [unused_variable('c', 2, 41)])
def test_aliased_field_target_not_defined(): expect_fails_rule( FieldsOnCorrectType, ''' fragment aliasedFieldTargetNotDefined on Dog { volume : mooVolume } ''', [undefined_field('mooVolume', 'Dog', 3, 9)])
def test_scalar_selection_not_allowed_with_directives(): expect_fails_rule(ScalarLeafs, ''' fragment scalarSelectionsNotAllowedWithDirectives on Dog { name @include(if: true) { isAlsoHumanName } } ''', [ no_scalar_subselection('name', 'String', 3, 33) ])
def test_enum_is_invalid_fragment_type(): expect_fails_rule(FragmentsOnCompositeTypes, ''' fragment scalarFragment on FurColor { bad } ''', [ fragment_on_non_composite_error('scalarFragment', 'FurColor', 2, 34) ])
def test_duplicate_input_object_fields(): expect_fails_rule(UniqueInputFieldNames, ''' { field(arg: { f1: "value", f1: "value" }) } ''', [ duplicate_field("f1", L(3, 22), L(3, 35)) ])
def test_aliased_lying_field_target_not_defined(): expect_fails_rule(FieldsOnCorrectType, ''' fragment aliasedLyingFieldTargetNotDefined on Dog { barkVolume : kawVolume } ''', [ undefined_field('kawVolume', 'Dog', 3, 9) ])
def test_variable_not_used(): expect_fails_rule(NoUnusedVariables, ''' query Foo($a: String, $b: String, $c: String) { field(a: $a, b: $b) } ''', [ unused_variable('c', 2, 41) ])
def test_invalid_arg_name(): expect_fails_rule(KnownArgumentNames, ''' fragment invalidArgName on Dog { doesKnowCommand(unknown: true) } ''', [ unknown_arg('unknown', 'doesKnowCommand', 'Dog', 3, 25) ])
def test_variable_not_defined(): expect_fails_rule(NoUndefinedVariables, ''' query Foo($a: String, $b: String, $c: String) { field(a: $a, b: $b, c: $c, d: $d) } ''', [ undefined_var('d', 3, 39) ])
def test_not_defined_on_interface(): expect_fails_rule(FieldsOnCorrectType, ''' fragment notDefinedOnInterface on Pet { tailLength } ''', [ undefined_field('tailLength', 'Pet', 3, 9) ])
def test_scalar_selection_not_allowed_with_directives_and_args(): expect_fails_rule(ScalarLeafs, ''' fragment scalarSelectionsNotAllowedWithDirectivesAndArgs on Dog { doesKnowCommand(dogCommand: SIT) @include(if: true) { sinceWhen } } ''', [ no_scalar_subselection('doesKnowCommand', 'Boolean', 3, 61) ])
def test_undirective_args_are_invalid(): expect_fails_rule(KnownArgumentNames, ''' { dog @skip(unless: true) } ''', [ unknown_directive_arg('unless', 'skip', 3, 19) ])
def test_defined_on_implementors_but_not_on_interface(): expect_fails_rule(FieldsOnCorrectType, ''' fragment definedOnImplementorsButNotInterface on Pet { nickname } ''', [ undefined_field('nickname', 'Pet', 3, 9) ])
def test_scalar_is_invalid_fragment_type(): expect_fails_rule(FragmentsOnCompositeTypes, ''' fragment scalarFragment on Boolean { bad } ''', [ fragment_on_non_composite_error('scalarFragment', 'Boolean', 2, 34) ])
def test_direct_field_selection_on_union(): expect_fails_rule(FieldsOnCorrectType, ''' fragment directFieldSelectionOnUnion on CatOrDog { directField } ''', [ undefined_field('directField', 'CatOrDog', 3, 9) ])
def test_input_object_is_invalid_fragment_type(): expect_fails_rule(FragmentsOnCompositeTypes, ''' fragment inputFragment on ComplexInput { stringField } ''', [ fragment_on_non_composite_error('inputFragment', 'ComplexInput', 2, 33) ])
def test_scalar_selection_not_allowed_on_enum(): expect_fails_rule(ScalarLeafs, ''' fragment scalarSelectionsNotAllowedOnEnum on Cat { furColor { inHexdec } } ''', [ no_scalar_subselection('furColor', 'FurColor', 3, 18) ])
def test_defined_on_implementors_queried_on_union(): expect_fails_rule(FieldsOnCorrectType, ''' fragment definedOnImplementorsQueriedOnUnion on CatOrDog { name } ''', [ undefined_field('name', 'CatOrDog', 3, 9) ])
def test_scalar_selection_not_allowed_with_args(): expect_fails_rule(ScalarLeafs, ''' fragment scalarSelectionsNotAllowedWithArgs on Dog { doesKnowCommand(dogCommand: SIT) { sinceWhen } } ''', [ no_scalar_subselection('doesKnowCommand', 'Boolean', 3, 42) ])
def test_field_not_defined_on_fragment(): expect_fails_rule(FieldsOnCorrectType, ''' fragment fieldNotDefined on Dog { meowVolume } ''', [ undefined_field('meowVolume', 'Dog', 3, 9) ])
def test_scalar_selection_not_allowed_on_boolean(): expect_fails_rule(ScalarLeafs, ''' fragment scalarSelectionsNotAllowedOnBoolean on Dog { barks { sinceWhen } } ''', [ no_scalar_subselection('barks', 'Boolean', 3, 15) ])
def variable_not_defined_by_unnamed_query(): expect_fails_rule(NoUndefinedVariables, ''' { field(a: $a) } ''', [ undefined_var('a', 3, 18) ])
def test_aliased_field_target_not_defined(): expect_fails_rule(FieldsOnCorrectType, ''' fragment aliasedFieldTargetNotDefined on Dog { volume : mooVolume } ''', [ undefined_field('mooVolume', 'Dog', 3, 9) ])