Skip to content

Commit

Permalink
Add test with spliting variables from fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-sop committed Sep 1, 2023
1 parent 405e7d5 commit 4997a22
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions tests/test_proxy_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,3 +682,90 @@ async def test_proxy_schema_splits_variables_between_schemas(
"""
).strip(),
}


@pytest.mark.asyncio
async def test_proxy_schema_splits_variables_from_fragments_between_schemas(
httpx_mock,
search_schema_json,
store_schema_json,
search_root_value,
store_root_value,
):
httpx_mock.add_response(
url="http://graphql.example.com/search/", json=search_schema_json
)
httpx_mock.add_response(
url="http://graphql.example.com/store/", json=store_schema_json
)
httpx_mock.add_response(
url="http://graphql.example.com/search/",
json={"data": search_root_value},
)
httpx_mock.add_response(
url="http://graphql.example.com/store/",
json={"data": store_root_value},
)

proxy_schema = ProxySchema()
proxy_schema.add_remote_schema("http://graphql.example.com/search/")
proxy_schema.add_remote_schema("http://graphql.example.com/store/")
proxy_schema.get_final_schema()

await proxy_schema.root_resolver(
{},
"TestQuery",
{"searchQuery": "test", "orderId": "testId"},
parse(
"""
query TestQuery($searchQuery: String!, $orderId: ID!) {
...searchFragment
...orderFragment
}
fragment searchFragment on Query {
search(query: $searchQuery) {
id
}
}
fragment orderFragment on Query {
order(id: $orderId) {
id
}
}
"""
),
)

search_request = httpx_mock.get_requests(url="http://graphql.example.com/search/")[
-1
]
store_request = httpx_mock.get_requests(url="http://graphql.example.com/store/")[-1]

assert json.loads(search_request.content) == {
"operationName": "TestQuery",
"variables": {"searchQuery": "test"},
"query": dedent(
"""
query TestQuery($searchQuery: String!) {
search(query: $searchQuery) {
id
}
}
"""
).strip(),
}
assert json.loads(store_request.content) == {
"operationName": "TestQuery",
"variables": {"orderId": "testId"},
"query": dedent(
"""
query TestQuery($orderId: ID!) {
order(id: $orderId) {
id
}
}
"""
).strip(),
}

0 comments on commit 4997a22

Please sign in to comment.