Skip to content

Commit

Permalink
Add test with spliting variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-sop committed Sep 1, 2023
1 parent 0a53358 commit e5990ac
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions tests/test_proxy_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,3 +603,82 @@ async def test_proxy_schema_unpacks_fragment_in_query(
"""
).strip(),
}


@pytest.mark.asyncio
async def test_proxy_schema_splits_variables_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!) {
search(query: $searchQuery) {
id
}
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 e5990ac

Please sign in to comment.