Skip to content

Commit

Permalink
Merge pull request #104 from evo-company/fix-federation-introspection…
Browse files Browse the repository at this point in the history
…-for-partial-queries

fix federation introspection for partial queries
  • Loading branch information
kindermax committed Jun 7, 2023
2 parents 51fd8f4 + 7fbed8e commit 3bd8914
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 31 deletions.
7 changes: 2 additions & 5 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ build:
os: ubuntu-20.04
tools:
python: "3.10"
jobs:
post_create_environment:
- pip install pdm==2.6
post_install:
- pdm sync -G docs
commands:
- pip install pdm==2.6
- pdm sync -G docs
- pdm run docs
- mv docs/build _readthedocs/html

53 changes: 27 additions & 26 deletions hiku/federation/introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,34 @@ def extend_with_federation(graph: Graph, data: dict) -> None:
if get_keys(graph, node.name):
union_types.append(_obj(node.name))

data["__schema"]["types"].append(_type("_Any", "SCALAR"))
data["__schema"]["types"].append(_type("_FieldSet", "SCALAR"))
data["__schema"]["types"].append(
_type("_Entity", "UNION", possibleTypes=union_types)
)
data["__schema"]["types"].append(
_type(
"_Service",
"OBJECT",
fields=[_field("sdl", _type("String", "SCALAR"))],
if "types" in data["__schema"]:
data["__schema"]["types"].append(_type("_Any", "SCALAR"))
data["__schema"]["types"].append(_type("_FieldSet", "SCALAR"))
data["__schema"]["types"].append(
_type("_Entity", "UNION", possibleTypes=union_types)
)
)

entities_field = _field(
"_entities",
_seq_of_nullable(_union("_Entity", union_types)),
args=[_ival("representations", _seq_of(_type("_Any", "SCALAR")))],
)

service_field = _field(
"_service",
_non_null(_obj("_Service")),
)
for t in data["__schema"]["types"]:
if t["kind"] == "OBJECT" and t["name"] == "Query":
t["fields"].append(entities_field)
t["fields"].append(service_field)
data["__schema"]["types"].append(
_type(
"_Service",
"OBJECT",
fields=[_field("sdl", _type("String", "SCALAR"))],
)
)

entities_field = _field(
"_entities",
_seq_of_nullable(_union("_Entity", union_types)),
args=[_ival("representations", _seq_of(_type("_Any", "SCALAR")))],
)

service_field = _field(
"_service",
_non_null(_obj("_Service")),
)
for t in data["__schema"]["types"]:
if t["kind"] == "OBJECT" and t["name"] == "Query":
t["fields"].append(entities_field)
t["fields"].append(service_field)


class BaseFederatedGraphQLIntrospection(GraphQLIntrospection):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_federation/test_introspection_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,19 @@ def test_federated_introspection_v2():
])
got = introspect_v2(GRAPH)
assert exp == got['data']


def test_introspection_partial_query():
query = """
query IntrospectionQuery {
__schema {
queryType { name }
}
}
"""
got = execute_v2(GRAPH, {'query': query})
assert got['data'] == {
'__schema': {
'queryType': {'name': 'Query'}
}
}

0 comments on commit 3bd8914

Please sign in to comment.