Test customization with update_remote_schema

https://github.com/hasura/graphql-engine-mono/pull/1971

GitOrigin-RevId: 617f15193e1149d08327d3a7eb0b21e11e280561
This commit is contained in:
David Overton 2021-08-02 15:49:46 +10:00 committed by hasura-bot
parent b713d9b13f
commit 3e1e0773fe
3 changed files with 78 additions and 4 deletions

View File

@ -117,7 +117,25 @@ An example request as follows:
"url": "https://remote-server.com/graphql",
"headers": [{"name": "X-Server-Request-From", "value": "Hasura"}],
"forward_client_headers": false,
"timeout_seconds": 60
"timeout_seconds": 60,
"customization": {
"root_fields_namespace": "some_field_name",
"type_names": {
"prefix": "some_type_name_prefix",
"suffix": "some_type_name_suffix",
"mapping": {
"some_type_name": "some_new_type_name"
}
},
"field_names": [ {
"parent_type": "some_type_name",
"prefix": "some_field_name_prefix",
"suffix": "some_field_name_suffix",
"mapping": {
"some_field_name": "some_new_field_name"
}
} ]
}
},
"comment": "some optional comment"
}

View File

@ -0,0 +1,11 @@
description: Simple GraphQL query
url: /v1/graphql
status: 200
response:
data:
my_hello: Hello me
query:
query: |
query {
my_hello(arg: "me")
}

View File

@ -33,7 +33,7 @@ def mk_add_remote_q(name, url, headers=None, client_hdrs=False, timeout=None, cu
def type_prefix_customization(type_prefix, mapping={}):
return { "type_names": {"prefix": type_prefix, "mapping": mapping }}
def mk_update_remote_q(name, url, headers=None, client_hdrs=False, timeout=None):
def mk_update_remote_q(name, url, headers=None, client_hdrs=False, timeout=None, customization=None):
return {
"type": "update_remote_schema",
"args": {
@ -43,7 +43,8 @@ def mk_update_remote_q(name, url, headers=None, client_hdrs=False, timeout=None)
"url": url,
"headers": headers,
"forward_client_headers": client_hdrs,
"timeout_seconds": timeout
"timeout_seconds": timeout,
"customization": customization
}
}
}
@ -90,7 +91,7 @@ class TestRemoteSchemaBasic:
st_code, resp = hge_ctx.v1q(export_metadata_q)
assert st_code == 200, resp
assert resp['remote_schemas'][0]['name'] == "simple 1"
def test_update_schema_with_no_url_change(self, hge_ctx):
""" call update_remote_schema API and check the details stored in metadata """
q = mk_update_remote_q('simple 1', 'http://localhost:5000/hello-graphql', None, True, 120)
@ -127,6 +128,50 @@ class TestRemoteSchemaBasic:
st_code, resp = hge_ctx.v1q(q)
assert st_code == 200, resp
def test_update_schema_with_customization_change(self, hge_ctx):
""" call update_remote_schema API and check the details stored in metadata """
customization = {'type_names': { 'prefix': 'Foo', 'mapping': {'String': 'MyString'}}, 'field_names': [{'parent_type': 'Hello', 'prefix': 'my_', 'mapping': {}}]}
q = mk_update_remote_q('simple 1', 'http://localhost:5000/hello-graphql', None, False, 60, customization=customization)
st_code, resp = hge_ctx.v1q(q)
# This should succeed since there isn't any conflicting relations or permissions set up
assert st_code == 200, resp
st_code, resp = hge_ctx.v1q(export_metadata_q)
assert st_code == 200, resp
assert resp['remote_schemas'][0]['name'] == "simple 1"
assert resp['remote_schemas'][0]['definition']['url'] == 'http://localhost:5000/hello-graphql'
assert resp['remote_schemas'][0]['definition']['timeout_seconds'] == 60
assert resp['remote_schemas'][0]['definition']['customization'] == customization
with open('queries/graphql_introspection/introspection.yaml') as f:
query = yaml.safe_load(f)
resp, _ = check_query(hge_ctx, query)
assert check_introspection_result(resp, ['MyString'], ['my_hello'])
check_query_f(hge_ctx, self.dir + '/basic_query_customized.yaml')
""" revert to original config for remote schema """
q = mk_update_remote_q('simple 1', 'http://localhost:5000/hello-graphql', None, False, 60)
st_code, resp = hge_ctx.v1q(q)
assert st_code == 200, resp
st_code, resp = hge_ctx.v1q(export_metadata_q)
assert st_code == 200, resp
assert 'customization' not in resp['remote_schemas'][0]['definition']
def test_update_schema_with_customization_change_invalid(self, hge_ctx):
""" call update_remote_schema API and check the details stored in metadata """
customization = {'type_names': { 'mapping': {'String': 'Foo', 'Hello': 'Foo'} } }
q = mk_update_remote_q('simple 1', 'http://localhost:5000/hello-graphql', None, False, 60, customization=customization)
st_code, resp = hge_ctx.v1q(q)
assert st_code == 400, resp
assert resp['error'] == 'Inconsistent object: Type name mappings are not distinct; the following types appear more than once: "Foo"'
""" revert to original config for remote schema """
q = mk_update_remote_q('simple 1', 'http://localhost:5000/hello-graphql', None, False, 60)
st_code, resp = hge_ctx.v1q(q)
assert st_code == 200, resp
@pytest.mark.allow_server_upgrade_test
def test_introspection(self, hge_ctx):
#check_query_f(hge_ctx, 'queries/graphql_introspection/introspection.yaml')