Skip to content

Commit 77cd2fc

Browse files
committed
bugfix: fix make schema with federation
1 parent 35cad75 commit 77cd2fc

File tree

2 files changed

+22
-55
lines changed

2 files changed

+22
-55
lines changed

examples/t.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

gql/schema.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,32 @@ def make_schema(
4242
sdl = purge_schema_directives(type_defs)
4343

4444
# remove subscription because Apollo Federation not support subscription yet.
45-
sdl = remove_subscription(type_defs)
45+
# type_defs = remove_subscription(type_defs)
4646

4747
type_defs = join_type_defs([type_defs, federation_service_type_defs])
4848
schema = build_schema(
4949
type_defs, assume_valid, assume_valid_sdl, no_location, experimental_fragment_variables
5050
)
51-
fix_federation_schema(schema)
51+
entity_types = get_entity_types(schema)
52+
if entity_types:
53+
schema = extend_schema(schema, parse(federation_entity_type_defs))
54+
55+
# Add _entities query.
56+
entity_type = schema.get_type("_Entity")
57+
if entity_type:
58+
entity_type = cast(GraphQLUnionType, entity_type)
59+
entity_type.types = entity_types
60+
61+
query_type = schema.get_type("Query")
62+
if query_type:
63+
query_type = cast(GraphQLObjectType, query_type)
64+
query_type.fields["_entities"].resolve = resolve_entities
65+
66+
# Add _service query.
67+
query_type = schema.get_type("Query")
68+
if query_type:
69+
query_type = cast(GraphQLObjectType, query_type)
70+
query_type.fields["_service"].resolve = lambda _service, info: {"sdl": sdl}
5271
else:
5372
schema = build_schema(
5473
type_defs, assume_valid, assume_valid_sdl, no_location, experimental_fragment_variables
@@ -125,27 +144,4 @@ def make_schema_from_path(
125144
experimental_fragment_variables,
126145
federation,
127146
directives,
128-
)
129-
130-
131-
def fix_federation_schema(schema: GraphQLSchema):
132-
entity_types = get_entity_types(schema)
133-
if entity_types:
134-
schema = extend_schema(schema, parse(federation_entity_type_defs))
135-
136-
# Add _entities query.
137-
entity_type = schema.get_type("_Entity")
138-
if entity_type:
139-
entity_type = cast(GraphQLUnionType, entity_type)
140-
entity_type.types = entity_types
141-
142-
query_type = schema.get_type("Query")
143-
if query_type:
144-
query_type = cast(GraphQLObjectType, query_type)
145-
query_type.fields["_entities"].resolve = resolve_entities
146-
147-
# Add _service query.
148-
query_type = schema.get_type("Query")
149-
if query_type:
150-
query_type = cast(GraphQLObjectType, query_type)
151-
query_type.fields["_service"].resolve = lambda _service, info: {"sdl": sdl}
147+
)

0 commit comments

Comments
 (0)