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:
paritosh-08 2022-03-03 19:03:43 +05:30 committed by hasura-bot
parent cd483f3389
commit a0c83b8e99
10 changed files with 84 additions and 29 deletions

View File

@ -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.

View File

@ -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",

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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) =>

View File

@ -4,3 +4,6 @@ status: 200
query:
type: reload_metadata
args: {}
response:
is_consistent: true
message: success

View File

@ -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

View File

@ -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'])))

View File

@ -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