mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-13 19:33:55 +03:00
server: add inconsistency information in reload_metadata
API call
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3860 GitOrigin-RevId: 02d1963946d69fdf6886aa61806eb71db60f8931
This commit is contained in:
parent
cd483f3389
commit
a0c83b8e99
@ -9,6 +9,7 @@
|
||||
### Bug fixes and improvements
|
||||
(Add entries below in the order of server, console, cli, docs, others)
|
||||
|
||||
- server: add metadata inconsistency information in `reload_metadata` API call
|
||||
- server: add custom function for case insensitive lookup in session variable in request transformation
|
||||
- server: Webhook Tranforms can now produce `x-www-url-formencoded` bodies.
|
||||
- server: Webhook Transforms can now delete request/response bodies explicitly.
|
||||
|
@ -123,8 +123,8 @@ func TestClient_ReloadMetadata(t *testing.T) {
|
||||
{
|
||||
name: "can reload metadata v2",
|
||||
want: `{
|
||||
"message": "success"
|
||||
}`,
|
||||
"message": "success"
|
||||
}`,
|
||||
fields: fields{
|
||||
Client: testutil.NewHttpcClient(t, portHasuraV13, nil),
|
||||
path: "v1/query",
|
||||
@ -135,8 +135,9 @@ func TestClient_ReloadMetadata(t *testing.T) {
|
||||
{
|
||||
name: "can reload metadata v3",
|
||||
want: `{
|
||||
"message": "success"
|
||||
}`,
|
||||
"is_consistent": true,
|
||||
"message": "success"
|
||||
}`,
|
||||
fields: fields{
|
||||
Client: testutil.NewHttpcClient(t, portHasuraLatest, nil),
|
||||
path: "v1/metadata",
|
||||
|
@ -254,7 +254,10 @@ func TestProjectMetadata_Reload(t *testing.T) {
|
||||
projectDirectory: "testdata/projectv3",
|
||||
endpointString: hgeEndpoint,
|
||||
},
|
||||
`{"message": "success"}`,
|
||||
`{
|
||||
"is_consistent": true,
|
||||
"message": "success"
|
||||
}`,
|
||||
require.NoError,
|
||||
},
|
||||
// TODO: automate the following tests
|
||||
|
@ -238,6 +238,37 @@ table using ``psql`` and this column should now be added to the GraphQL schema.
|
||||
}
|
||||
}
|
||||
|
||||
Response:
|
||||
|
||||
If the metadata is consistent:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"is_consistent": true,
|
||||
"message": "success"
|
||||
}
|
||||
|
||||
If the metadata is not consistent:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"is_consistent": false,
|
||||
"message": "success",
|
||||
"inconsistent_objects": [
|
||||
{
|
||||
"definition": {
|
||||
"schema": "public",
|
||||
"name": "article"
|
||||
},
|
||||
"name": "table article in source default",
|
||||
"reason": "Inconsistent object: no such table/view exists in source: \"article\"",
|
||||
"type": "table"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
.. _metadata_reload_metadata_syntax:
|
||||
|
||||
Args syntax
|
||||
|
@ -153,6 +153,37 @@ table using ``psql`` and this column should now be added to the GraphQL schema.
|
||||
}
|
||||
}
|
||||
|
||||
Response:
|
||||
|
||||
If the metadata is consistent:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"is_consistent": true,
|
||||
"message": "success"
|
||||
}
|
||||
|
||||
If the metadata is not consistent:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"is_consistent": false,
|
||||
"message": "success",
|
||||
"inconsistent_objects": [
|
||||
{
|
||||
"definition": {
|
||||
"schema": "public",
|
||||
"name": "article"
|
||||
},
|
||||
"name": "table article in source default",
|
||||
"reason": "Inconsistent object: no such table/view exists in source: \"article\"",
|
||||
"type": "table"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
.. _schema_metadata_reload_metadata_syntax:
|
||||
|
||||
Args syntax
|
||||
|
@ -367,7 +367,12 @@ runReloadMetadata (ReloadMetadata reloadRemoteSchemas reloadSources reloadRecrea
|
||||
}
|
||||
|
||||
buildSchemaCacheWithOptions (CatalogUpdate $ Just recreateEventTriggersSources) cacheInvalidations metadata
|
||||
pure successMsg
|
||||
inconsObjs <- scInconsistentObjs <$> askSchemaCache
|
||||
pure . encJFromJValue . J.object $
|
||||
[ ("message" :: Text) J..= ("success" :: Text),
|
||||
"is_consistent" J..= null inconsObjs
|
||||
]
|
||||
<> ["inconsistent_objects" J..= inconsObjs | not (null inconsObjs)]
|
||||
|
||||
runDumpInternalState ::
|
||||
(QErrM m, CacheRM m) =>
|
||||
|
@ -4,3 +4,6 @@ status: 200
|
||||
query:
|
||||
type: reload_metadata
|
||||
args: {}
|
||||
response:
|
||||
is_consistent: true
|
||||
message: success
|
||||
|
@ -25,11 +25,8 @@
|
||||
query:
|
||||
type: reload_metadata
|
||||
args: {}
|
||||
|
||||
- description: Query inconsistent objects
|
||||
url: /v1/query
|
||||
status: 200
|
||||
response:
|
||||
message: success
|
||||
is_consistent: false
|
||||
inconsistent_objects:
|
||||
- definition:
|
||||
@ -51,9 +48,6 @@
|
||||
reason: 'Inconsistent object: table "colors" is not tracked'
|
||||
name: object_relation favorite_color_object in table employees in source default
|
||||
type: object_relation
|
||||
query:
|
||||
type: get_inconsistent_metadata
|
||||
args: {}
|
||||
|
||||
- description: Drop inconsistent objects
|
||||
url: /v1/query
|
||||
|
@ -7,10 +7,6 @@ yaml=YAML(typ='safe', pure=True)
|
||||
|
||||
class TestInconsistentObjects():
|
||||
|
||||
get_inconsistent_metadata = {
|
||||
"type": "get_inconsistent_metadata",
|
||||
"args": {}
|
||||
}
|
||||
reload_metadata = {
|
||||
"type": "reload_metadata",
|
||||
"args": {}
|
||||
@ -39,10 +35,7 @@ class TestInconsistentObjects():
|
||||
# reload metadata
|
||||
st_code, resp = hge_ctx.v1q(q=self.reload_metadata)
|
||||
assert st_code == 200, resp
|
||||
|
||||
# fetch inconsistent objects
|
||||
st_code, resp = hge_ctx.v1q(q=self.get_inconsistent_metadata)
|
||||
assert st_code == 200, resp
|
||||
# check inconsistent objects
|
||||
incons_objs_test = test['inconsistent_objects']
|
||||
incons_objs_resp = resp['inconsistent_objects']
|
||||
|
||||
@ -74,13 +67,8 @@ class TestInconsistentObjects():
|
||||
# reload metadata
|
||||
st_code, resp = hge_ctx.v1q(q=self.reload_metadata)
|
||||
assert st_code == 200, resp
|
||||
|
||||
# fetch inconsistent objects
|
||||
st_code, resp = hge_ctx.v1q(q=self.get_inconsistent_metadata)
|
||||
assert st_code == 200, resp
|
||||
|
||||
# check inconsistent objects
|
||||
assert resp['is_consistent'] == True, resp
|
||||
assert len(resp['inconsistent_objects']) == 0, resp
|
||||
|
||||
# teardown
|
||||
st_code, resp = hge_ctx.v1q(json.loads(json.dumps(test['teardown'])))
|
||||
|
@ -709,8 +709,6 @@ class TestRemoteSchemaReload:
|
||||
st_code, resp = hge_ctx.v1q(reload_metadata_q)
|
||||
assert st_code == 200, resp
|
||||
# Check if the remote schema present in inconsistent metadata
|
||||
st_code, resp = hge_ctx.v1q(get_inconsistent_metadata_q)
|
||||
assert st_code == 200, resp
|
||||
assert resp['is_consistent'] == False, resp
|
||||
assert resp['inconsistent_objects'][0]['type'] == 'remote_schema', resp
|
||||
# Restart remote graphql server
|
||||
|
Loading…
Reference in New Issue
Block a user