Ejemplo n.º 1
0
    def test_can_handle_recursive_types(self):
        obj_1 = GraphQLObjectType("Object", fields=lambda: {"self": GraphQLField(type=obj_1)})
        obj_2 = GraphQLObjectType("Object", fields=lambda: {"self": GraphQLField(type=obj_2)})

        assert is_subtype(obj_1, obj_2)

        obj_1 = GraphQLObjectType("Object", fields=lambda: {"self": GraphQLField(type=obj_1)})
        obj_2 = GraphQLObjectType("Object", fields=lambda: {"self": GraphQLField(type=GraphQLNonNull(obj_2))})

        assert not is_subtype(obj_1, obj_2)
Ejemplo n.º 2
0
    def _assert_merge(self, types, expected_type):
        merged = _common_supertype(*types)
        assert_that(merged, expected_type)
        assert_that(_common_supertype(*list(reversed(types))), expected_type)

        for type_ in types:
            assert is_subtype(type_, merged)
Ejemplo n.º 3
0
    def _assert_merge(self, types, expected_type):
        merged = greatest_common_subtype(types)
        assert_that(merged, expected_type)
        assert_that(greatest_common_subtype(list(reversed(types))), expected_type)

        for type_ in types:
            assert is_subtype(merged, type_)
Ejemplo n.º 4
0
 def test_when_query_is_not_subtype_then_schema_is_not_subtype(self):
     assert not is_subtype(
         GraphQLSchema(
             query=GraphQLObjectType("Object", fields={
                 "id": GraphQLField(type=GraphQLInt),
             }),
         ),
         GraphQLSchema(
             query=GraphQLObjectType("Object", fields={
                 "id": GraphQLField(type=GraphQLInt),
                 "name": GraphQLField(type=GraphQLString),
             }),
         ),
     )
Ejemplo n.º 5
0
 def test_when_arg_is_missing_then_is_not_subtype(self):
     assert not is_subtype(
         GraphQLObjectType("Object", {
             "value": GraphQLField(
                 type=GraphQLNonNull(GraphQLInt),
                 args={},
             )
         }),
         GraphQLObjectType("Object", {
             "value": GraphQLField(
                 type=GraphQLNonNull(GraphQLInt),
                 args={"id": GraphQLArgument(type=GraphQLInt)},
             )
         }),
     )
Ejemplo n.º 6
0
 def test_when_field_has_extra_non_null_args_then_is_not_subtype(self):
     assert not is_subtype(
         GraphQLObjectType("Object", {
             "value": GraphQLField(
                 type=GraphQLNonNull(GraphQLInt),
                 args={"id": GraphQLArgument(type=GraphQLNonNull(GraphQLInt))},
             )
         }),
         GraphQLObjectType("Object", {
             "value": GraphQLField(
                 type=GraphQLNonNull(GraphQLInt),
                 args={},
             )
         }),
     )
Ejemplo n.º 7
0
 def test_when_field_has_arg_of_supertype_then_is_subtype(self):
     assert is_subtype(
         GraphQLObjectType("Object", {
             "value": GraphQLField(
                 type=GraphQLNonNull(GraphQLInt),
                 args={"id": GraphQLArgument(type=GraphQLInt)},
             )
         }),
         GraphQLObjectType("Object", {
             "value": GraphQLField(
                 type=GraphQLNonNull(GraphQLInt),
                 args={"id": GraphQLArgument(type=GraphQLNonNull(GraphQLInt))},
             )
         }),
     )
Ejemplo n.º 8
0
 def test_when_mutation_is_missing_then_is_not_subtype_of_schema_with_mutation(self):
     assert not is_subtype(
         GraphQLSchema(
             query=GraphQLObjectType("Object", fields={
                 "id": GraphQLField(type=GraphQLInt),
             }),
         ),
         GraphQLSchema(
             query=GraphQLObjectType("Object", fields={
                 "id": GraphQLField(type=GraphQLInt),
             }),
             mutation=GraphQLObjectType("Mutation", fields={
                 "id": GraphQLField(type=GraphQLInt),
             }),
         ),
     )
Ejemplo n.º 9
0
 def test_list_of_type_is_not_subtype_of_list_of_subtype(self):
     assert not is_subtype(GraphQLList(GraphQLInt), GraphQLList(GraphQLNonNull(GraphQLInt)))
Ejemplo n.º 10
0
 def test_list_of_type_is_subtype_of_list_of_same_type(self):
     assert is_subtype(GraphQLList(GraphQLInt), GraphQLList(GraphQLInt))
Ejemplo n.º 11
0
 def test_non_null_type_is_not_subtype_of_different_null_type(self):
     assert not is_subtype(GraphQLNonNull(GraphQLInt), GraphQLString)
Ejemplo n.º 12
0
 def test_non_null_type_is_subtype_of_same_null_type(self):
     assert is_subtype(GraphQLNonNull(GraphQLInt), GraphQLInt)
Ejemplo n.º 13
0
 def test_scalar_types_are_not_subtypes_of_other_types(self, subtype, supertype):
     assert not is_subtype(subtype, supertype)
Ejemplo n.º 14
0
 def test_when_object_type_has_same_name_and_has_different_field_name_then_it_is_not_a_subtype(self):
     assert not is_subtype(
         GraphQLObjectType("Object", fields={"id": GraphQLField(type=GraphQLString)}),
         GraphQLObjectType("Object", fields={"name": GraphQLField(type=GraphQLString)}),
     )
Ejemplo n.º 15
0
 def test_when_object_type_field_is_of_different_type_then_it_is_not_a_subtype(self, object_type):
     assert not is_subtype(
         object_type("Object", {"id": GraphQLString}),
         object_type("Object", {"id": GraphQLInt}),
     )
Ejemplo n.º 16
0
 def test_when_object_types_have_different_names_then_they_are_not_subtypes(self, object_type):
     assert not is_subtype(
         object_type("First", {"id": GraphQLInt}),
         object_type("Second", {"id": GraphQLInt}),
     )
Ejemplo n.º 17
0
 def test_when_input_object_is_missing_non_null_field_then_it_is_not_a_subtype(self):
     assert not is_subtype(
         GraphQLInputObjectType("Object", {"id": GraphQLInputObjectField(type=GraphQLInt)}),
         GraphQLInputObjectType("Object", {"id": GraphQLInputObjectField(type=GraphQLInt), "name": GraphQLInputObjectField(type=GraphQLNonNull(GraphQLString))}),
     )
Ejemplo n.º 18
0
 def test_when_input_object_type_has_same_name_and_superset_of_fields_then_it_is_a_subtype(self):
     assert is_subtype(
         GraphQLInputObjectType("Object", {"id": GraphQLInputObjectField(type=GraphQLInt), "name": GraphQLInputObjectField(type=GraphQLString)}),
         GraphQLInputObjectType("Object", {"id": GraphQLInputObjectField(type=GraphQLInt)}),
     )
Ejemplo n.º 19
0
 def test_when_object_types_have_same_name_and_fields_then_they_are_subtypes(self, object_type):
     assert is_subtype(
         object_type("Object", {"id": GraphQLInt}),
         object_type("Object", {"id": GraphQLInt}),
     )
Ejemplo n.º 20
0
 def test_scalar_types_are_subtypes_of_themselves(self, graphql_type):
     assert is_subtype(graphql_type, graphql_type)
Ejemplo n.º 21
0
 def test_object_type_field_can_be_subtype(self, object_type):
     assert is_subtype(
         object_type("Object", {"id": GraphQLNonNull(GraphQLInt)}),
         object_type("Object", {"id": GraphQLInt}),
     )
Ejemplo n.º 22
0
 def test_when_object_type_has_same_name_and_subset_of_fields_then_it_is_not_a_subtype(self):
     assert not is_subtype(
         GraphQLObjectType("Object", fields={"id": GraphQLField(type=GraphQLInt)}),
         GraphQLObjectType("Object", fields={"id": GraphQLField(type=GraphQLInt), "name": GraphQLField(type=GraphQLString)}),
     )