From a0c83b8e99d4c37a9c3473b6f9344ec054f18694 Mon Sep 17 00:00:00 2001 From: paritosh-08 <85472423+paritosh-08@users.noreply.github.com> Date: Thu, 3 Mar 2022 19:03:43 +0530 Subject: [PATCH] server: add inconsistency information in `reload_metadata` API call PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3860 GitOrigin-RevId: 02d1963946d69fdf6886aa61806eb71db60f8931 --- CHANGELOG.md | 1 + .../commonmetadata/commonmetadata_test.go | 9 +++--- cli/pkg/metadata/project_metadata_test.go | 5 ++- .../metadata-api/manage-metadata.rst | 31 +++++++++++++++++++ .../schema-metadata-api/manage-metadata.rst | 31 +++++++++++++++++++ server/src-lib/Hasura/RQL/DDL/Metadata.hs | 7 ++++- .../queries/v1/metadata/reload_metadata.yaml | 3 ++ ...tionship_with_inconsistent_enum_table.yaml | 8 +---- server/tests-py/test_inconsistent_meta.py | 16 ++-------- server/tests-py/test_schema_stitching.py | 2 -- 10 files changed, 84 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40e5438b211..ca79f9cabf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/cli/internal/hasura/commonmetadata/commonmetadata_test.go b/cli/internal/hasura/commonmetadata/commonmetadata_test.go index 5d1393891d1..d6d9fc90015 100644 --- a/cli/internal/hasura/commonmetadata/commonmetadata_test.go +++ b/cli/internal/hasura/commonmetadata/commonmetadata_test.go @@ -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", diff --git a/cli/pkg/metadata/project_metadata_test.go b/cli/pkg/metadata/project_metadata_test.go index cc7fe496e47..267279d21e2 100644 --- a/cli/pkg/metadata/project_metadata_test.go +++ b/cli/pkg/metadata/project_metadata_test.go @@ -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 diff --git a/docs/graphql/core/api-reference/metadata-api/manage-metadata.rst b/docs/graphql/core/api-reference/metadata-api/manage-metadata.rst index 537486401e1..b3be3eea746 100644 --- a/docs/graphql/core/api-reference/metadata-api/manage-metadata.rst +++ b/docs/graphql/core/api-reference/metadata-api/manage-metadata.rst @@ -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 diff --git a/docs/graphql/core/api-reference/schema-metadata-api/manage-metadata.rst b/docs/graphql/core/api-reference/schema-metadata-api/manage-metadata.rst index 8ed6e660b8a..1e0efc54f87 100644 --- a/docs/graphql/core/api-reference/schema-metadata-api/manage-metadata.rst +++ b/docs/graphql/core/api-reference/schema-metadata-api/manage-metadata.rst @@ -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 diff --git a/server/src-lib/Hasura/RQL/DDL/Metadata.hs b/server/src-lib/Hasura/RQL/DDL/Metadata.hs index 23faccabf90..a9580eebedb 100644 --- a/server/src-lib/Hasura/RQL/DDL/Metadata.hs +++ b/server/src-lib/Hasura/RQL/DDL/Metadata.hs @@ -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) => diff --git a/server/tests-py/queries/v1/metadata/reload_metadata.yaml b/server/tests-py/queries/v1/metadata/reload_metadata.yaml index 6f73682d3d7..3070ab939b9 100644 --- a/server/tests-py/queries/v1/metadata/reload_metadata.yaml +++ b/server/tests-py/queries/v1/metadata/reload_metadata.yaml @@ -4,3 +4,6 @@ status: 200 query: type: reload_metadata args: {} +response: + is_consistent: true + message: success diff --git a/server/tests-py/queries/v1/set_table_is_enum/relationship_with_inconsistent_enum_table.yaml b/server/tests-py/queries/v1/set_table_is_enum/relationship_with_inconsistent_enum_table.yaml index 4aa32dcfbc2..0a79d6d8217 100644 --- a/server/tests-py/queries/v1/set_table_is_enum/relationship_with_inconsistent_enum_table.yaml +++ b/server/tests-py/queries/v1/set_table_is_enum/relationship_with_inconsistent_enum_table.yaml @@ -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 diff --git a/server/tests-py/test_inconsistent_meta.py b/server/tests-py/test_inconsistent_meta.py index 5ced1c119c2..1738e98a896 100644 --- a/server/tests-py/test_inconsistent_meta.py +++ b/server/tests-py/test_inconsistent_meta.py @@ -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']))) diff --git a/server/tests-py/test_schema_stitching.py b/server/tests-py/test_schema_stitching.py index 6c16351b8fa..01696b62d25 100644 --- a/server/tests-py/test_schema_stitching.py +++ b/server/tests-py/test_schema_stitching.py @@ -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