2022-07-25 18:53:25 +03:00
|
|
|
#!/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.usefixtures('per_class_tests_db_state')
|
2022-09-29 20:18:49 +03:00
|
|
|
@pytest.mark.admin_secret
|
|
|
|
@pytest.mark.hge_env('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'apollo_federation')
|
2022-07-25 18:53:25 +03:00
|
|
|
class TestApolloFederation:
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def dir(cls):
|
|
|
|
return 'queries/apollo_federation'
|
|
|
|
|
2023-04-24 22:14:01 +03:00
|
|
|
@pytest.fixture
|
2023-04-25 15:49:31 +03:00
|
|
|
def federated_server_with_hge_only(self, worker_id: str, hge_url: str, hge_key: str):
|
|
|
|
server = NodeGraphQL(worker_id, 'remote_schemas/nodejs/apollo_federated_server_with_hge_only.js', env={
|
2022-09-28 12:19:47 +03:00
|
|
|
'HGE_URL': hge_url,
|
2022-09-29 20:18:49 +03:00
|
|
|
'HASURA_GRAPHQL_ADMIN_SECRET': hge_key,
|
2022-09-28 12:19:47 +03:00
|
|
|
})
|
2023-04-24 22:14:01 +03:00
|
|
|
server.start()
|
|
|
|
yield server
|
|
|
|
server.stop()
|
2022-07-25 18:53:25 +03:00
|
|
|
|
2023-04-24 22:14:01 +03:00
|
|
|
@pytest.fixture
|
2023-04-25 15:49:31 +03:00
|
|
|
def server_1(self, worker_id: str, hge_url: str):
|
|
|
|
server = NodeGraphQL(worker_id, 'remote_schemas/nodejs/apollo_server_1.js', env={
|
2023-04-24 22:14:01 +03:00
|
|
|
'HGE_URL': hge_url,
|
|
|
|
})
|
|
|
|
server.start()
|
|
|
|
yield server
|
|
|
|
server.stop()
|
|
|
|
|
|
|
|
@pytest.fixture
|
2023-04-25 15:49:31 +03:00
|
|
|
def federated_server_with_hge_and_server1(self, worker_id: str, hge_url: str, hge_key: str, server_1):
|
|
|
|
server = NodeGraphQL(worker_id, 'remote_schemas/nodejs/apollo_federated_server_with_hge_and_server1.js', env={
|
2023-04-24 22:14:01 +03:00
|
|
|
'HGE_URL': hge_url,
|
|
|
|
'OTHER_URL': server_1.url,
|
|
|
|
'HASURA_GRAPHQL_ADMIN_SECRET': hge_key,
|
|
|
|
})
|
|
|
|
server.start()
|
|
|
|
yield server
|
|
|
|
server.stop()
|
|
|
|
|
|
|
|
def test_apollo_federated_server_with_hge_only(self, federated_server_with_hge_only):
|
2022-07-25 18:53:25 +03:00
|
|
|
# run a GQL query
|
|
|
|
gql_query = """
|
|
|
|
query {
|
|
|
|
user_by_pk(id: 1) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
2023-04-24 22:14:01 +03:00
|
|
|
resp = make_request(federated_server_with_hge_only.url, gql_query)
|
2022-07-25 18:53:25 +03:00
|
|
|
|
|
|
|
# check if everything was okay
|
|
|
|
assert resp.status_code == 200, resp.text
|
|
|
|
assert 'data' in resp.text
|
|
|
|
|
2023-04-24 22:14:01 +03:00
|
|
|
def test_apollo_federated_server_with_hge_and_apollo_graphql_server(self, federated_server_with_hge_and_server1):
|
2022-07-25 18:53:25 +03:00
|
|
|
# run a GQL query
|
|
|
|
gql_query = """
|
|
|
|
query {
|
|
|
|
getUserData(id: 1) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
city
|
|
|
|
email
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
2023-04-24 22:14:01 +03:00
|
|
|
resp = make_request(federated_server_with_hge_and_server1.url, gql_query)
|
2022-07-25 18:53:25 +03:00
|
|
|
|
|
|
|
# check if everything was okay
|
|
|
|
assert resp.status_code == 200, resp.text
|
|
|
|
assert 'data' in resp.text
|
|
|
|
|
2022-09-29 20:18:49 +03:00
|
|
|
def test_apollo_federation_fields(self, hge_ctx):
|
2022-07-25 18:53:25 +03:00
|
|
|
check_query_f(hge_ctx, self.dir() + '/root_fields.yaml')
|
|
|
|
|
2022-09-29 20:18:49 +03:00
|
|
|
def test_apollo_federation_entities(self, hge_ctx):
|
2022-07-25 18:53:25 +03:00
|
|
|
check_query_f(hge_ctx, self.dir() + '/entities.yaml')
|