def test_reference_resolver_can_be_set_using_setter(schema): def resolve_result_type(*_): # pylint: disable=unused-variable return "Wine" interface = FederatedInterfaceType("Product") interface.set_type_resolver(resolve_result_type) interface.reference_resolver(lambda *_: {"name": "Malbec"}) interface.bind_to_schema(schema) obj = FederatedObjectType("Wine") obj.bind_to_schema(schema) result = graphql_sync( schema, """ query GetEntities($representations: [_Any!]!) { _entities(representations: $representations) { ... on Wine { name } } } """, variable_values={"representations": [{"__typename": "Wine", "upc": 1}]}, ) assert result.errors is None assert result.data["_entities"] == [{"name": "Malbec"}]
def test_federated_schema_mark_interface_with_multiple_keys(): type_defs = """ type Query interface Product @key(fields: "upc sku") { upc: String! sku: String! name: String price: Int } """ product = FederatedInterfaceType("Product") schema = make_federated_schema(type_defs, product) assert sic(print_interface(schema.get_type("Product"))) == sic(""" interface Product { upc: String! sku: String! name: String price: Int } """) assert schema.get_type("_Entity") is None
def test_bind_interface_to_invalid_type_raises_error(schema): interface = FederatedInterfaceType("Date") with pytest.raises(ValueError): interface.bind_to_schema(schema)
def test_bind_interface_to_undefined_type_raises_error(schema): interface = FederatedInterfaceType("Test") with pytest.raises(ValueError): interface.bind_to_schema(schema)