graphql-engine/server/tests-py/test_apollo_federation.py
Samir Talwar 8cb2738cbe server/tests-py: Declaratively state the HGE environment variables.
This has two purposes:

* When running the Python integration tests against a running HGE instance, with `--hge-url`, it will check the environment variables available and actively skip the test if they aren't set. This replaces the previous ad-hoc skip behavior.
* More interestingly, when running against a binary with `--hge-bin`, the environment variables are passed through, which means different tests can run with different environment variables.

  On top of this, the various services we use for testing now also provide their own environment variables, rather than expecting a test script to do it.

In order to make this work, I also had to invert the dependency between various services and `hge_ctx`. I extracted a `pg_version` fixture to provide the PostgreSQL version, and now pass the `hge_url` and `hge_key` explicitly to `ActionsWebhookServer`.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6028
GitOrigin-RevId: 16d866741dba5887da1adf4e1ade8182ccc9d344
2022-09-28 09:21:02 +00:00

88 lines
2.5 KiB
Python

#!/usr/bin/env python3
import pytest
import requests
from remote_server import NodeGraphQL
from validate import check_query_f
def make_request(url, query):
print('Sending request to the local federated server')
payload = {'query': query}
resp = requests.post(url, json=payload)
return resp
@pytest.mark.hge_env('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'apollo_federation')
@pytest.mark.usefixtures('per_class_tests_db_state')
class TestApolloFederation:
@classmethod
def dir(cls):
return 'queries/apollo_federation'
def test_apollo_federated_server_with_hge_only(self, hge_url: str):
# start the node server
fed_server = NodeGraphQL(["node", "remote_schemas/nodejs/apollo_federated_server_with_hge_only.js"], env={
'HGE_URL': hge_url,
})
fed_server.start()
# run a GQL query
gql_query = """
query {
user_by_pk(id: 1) {
id
name
}
}
"""
resp = make_request(fed_server.url, gql_query)
# stop the node server
fed_server.stop()
# check if everything was okay
assert resp.status_code == 200, resp.text
assert 'data' in resp.text
def test_apollo_federated_server_with_hge_and_apollo_graphql_server(self, hge_url: str):
# start the node servers
server_1 = NodeGraphQL(["node", "remote_schemas/nodejs/apollo_server_1.js"], env={
'HGE_URL': hge_url,
})
server_env = {
'HGE_URL': hge_url,
'OTHER_URL': server_1.url,
}
fed_server = NodeGraphQL(["node", "remote_schemas/nodejs/apollo_federated_server_with_hge_and_server1.js"], env=server_env)
server_1.start()
fed_server.start()
# run a GQL query
gql_query = """
query {
getUserData(id: 1) {
id
name
city
email
}
}
"""
resp = make_request(fed_server.url, gql_query)
# stop the node servers
fed_server.stop()
server_1.stop()
# check if everything was okay
assert resp.status_code == 200, resp.text
assert 'data' in resp.text
def test_apollo_federation_fields(self,hge_ctx):
check_query_f(hge_ctx, self.dir() + '/root_fields.yaml')
def test_apollo_federation_entities(self,hge_ctx):
check_query_f(hge_ctx, self.dir() + '/entities.yaml')