예제 #1
0
    def rejects_a_union_type_with_duplicated_member_type():
        schema = build_schema("""
            type Query {
              test: BadUnion
            }

            type TypeA {
              field: String
            }

            type TypeB {
              field: String
            }

            union BadUnion =
              | TypeA
              | TypeB
              | TypeA
            """)

        assert validate_schema(schema) == [{
            'message': 'Union type BadUnion can only include type TypeA once.',
            'locations': [(15, 17), (17, 17)]}]

        schema = extend_schema(schema, parse('extend union BadUnion = TypeB'))

        assert validate_schema(schema) == [{
            'message': 'Union type BadUnion can only include type TypeA once.',
            'locations': [(15, 17), (17, 17)]}, {
            'message': 'Union type BadUnion can only include type TypeB once.',
            'locations': [(16, 17), (1, 25)]}]
예제 #2
0
    def rejects_a_schema_whose_subscription_type_is_an_input_type():
        schema = build_schema("""
            type Query {
              field: String
            }

            input Subscription {
              test: String
            }
            """)
        assert validate_schema(schema) == [{
            'message': 'Subscription root type must be Object type if'
                       ' provided, it cannot be Subscription.',
            'locations': [(6, 13)]}]

        schema_with_def = build_schema("""
            schema {
              query: Query
              subscription: SomeInputObject
            }

            type Query {
              field: String
            }

            input SomeInputObject {
              test: String
            }
            """)
        assert validate_schema(schema_with_def) == [{
            'message': 'Subscription root type must be Object type if'
                       ' provided, it cannot be SomeInputObject.',
            'locations': [(4, 29)]}]
예제 #3
0
    def rejects_object_implementing_extended_interface_due_to_missing_args():
        schema = build_schema("""
            type Query {
              test: AnotherObject
            }

            interface AnotherInterface {
              field: String
            }

            type AnotherObject implements AnotherInterface {
              field: String
            }
            """)
        extended_schema = extend_schema(schema, parse("""
            extend interface AnotherInterface {
              newField(test: Boolean): String
            }

            extend type AnotherObject {
              newField: String
            }
        """))
        assert validate_schema(extended_schema) == [{
            'message': 'Interface field argument'
                       ' AnotherInterface.newField(test:) expected'
                       ' but AnotherObject.newField does not provide it.',
            'locations': [(3, 24), (7, 15)]}]
예제 #4
0
 def rejects_an_object_type_with_incorrectly_named_fields():
     schema = schema_with_field_type(GraphQLObjectType('SomeObject', {
         'bad-name-with-dashes': GraphQLField(GraphQLString)}))
     msg = validate_schema(schema)[0].message
     assert msg == (
         'Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/'
         " but 'bad-name-with-dashes' does not.")
예제 #5
0
 def rejects_a_schema_extended_with_invalid_root_types():
     schema = build_schema("""
         input SomeInputObject {
           test: String
         }
         """)
     schema = extend_schema(schema, parse("""
         extend schema {
           query: SomeInputObject
         }
         """))
     schema = extend_schema(schema, parse("""
         extend schema {
           mutation: SomeInputObject
         }
         """))
     schema = extend_schema(schema, parse("""
         extend schema {
           subscription: SomeInputObject
         }
         """))
     assert validate_schema(schema) == [{
         'message': 'Query root type must be Object type,'
                    ' it cannot be SomeInputObject.',
         'locations': [(3, 22)]
     }, {
         'message': 'Mutation root type must be Object type'
                    ' if provided, it cannot be SomeInputObject.',
         'locations': [(3, 25)]
     }, {
         'message': 'Subscription root type must be Object type'
                    ' if provided, it cannot be SomeInputObject.',
         'locations': [(3, 29)]
     }]