def test_union_type_resolver_may_be_set_using_setter(query_with_user_item): def resolve_result_type(*_): # pylint: disable=unused-variable return "User" union = UnionType("FeedItem") union.set_type_resolver(resolve_result_type) schema = make_executable_schema(type_defs, [query_with_user_item, union]) result = graphql_sync(schema, "{ item { __typename } }") assert result.data == {"item": {"__typename": "User"}}
def create_schema_from_template(self): template = SERVICE_TEMPLATE entity_union_str = self._make_entity_str() entity_query_str = "" if entity_union_str != "": entity_union = UnionType("_Entity") entity_union.set_type_resolver(self.resolve_entities) self.query.set_field("_entities", self._entities) entity_query_str = ENTITY_QUERY self.federation_types.append(entity_union) template = template.format(union_entities=entity_union_str, entity_query=entity_query_str, query_str=self.sdl) return make_executable_schema( template, [self.query, _Any, _FieldSet] + [ObjectType(entity_name) for entity_name in self.entities.keys()] + self.federation_types, directives=self.directives)