From 18d30359a3ac1ed6918a85fae682a17090de2130 Mon Sep 17 00:00:00 2001 From: pranshi06 <85474619+pranshi06@users.noreply.github.com> Date: Wed, 6 Dec 2023 18:39:43 +0530 Subject: [PATCH] server: fix condition to classify requests to Apollo persisted queries (cherry-pick) Cherry picks PR: https://github.com/hasura/graphql-engine-mono/pull/10514 PR-URL: https://github.com/hasura/graphql-engine-mono/pull/10536 GitOrigin-RevId: b60c7a30766bcbfab09db9989c131712a46fc6d7 --- server/src-lib/Hasura/Server/Types.hs | 4 +- .../basic/select_query_with_extensions.yaml | 49 +++++++++++++++++++ server/tests-py/test_graphql_queries.py | 4 ++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 server/tests-py/queries/graphql_query/basic/select_query_with_extensions.yaml diff --git a/server/src-lib/Hasura/Server/Types.hs b/server/src-lib/Hasura/Server/Types.hs index 26463cd6df0f5..33669272e9c15 100644 --- a/server/src-lib/Hasura/Server/Types.hs +++ b/server/src-lib/Hasura/Server/Types.hs @@ -328,8 +328,8 @@ instance ToJSON ExtQueryReqs where instance FromJSON ExtQueryReqs where parseJSON arr@Array {} = EqrGQLReq <$> (GH.GQLBatchedReqs <$> parseJSON arr) parseJSON json - -- The APQ requests, have a special key called as Extensions - | isJust (json Lens.^? key "extensions") = EqrAPQReq <$> parseJSON json + -- The APQ requests, have a special object in the key `Extentions` called as `persistedQuery` + | isJust (json Lens.^? key "extensions" . key "persistedQuery") = EqrAPQReq <$> parseJSON json | otherwise = EqrGQLReq <$> (GH.GQLSingleRequest <$> parseJSON json) class (Monad m) => MonadGetPolicies m where diff --git a/server/tests-py/queries/graphql_query/basic/select_query_with_extensions.yaml b/server/tests-py/queries/graphql_query/basic/select_query_with_extensions.yaml new file mode 100644 index 0000000000000..650e0776a3fe5 --- /dev/null +++ b/server/tests-py/queries/graphql_query/basic/select_query_with_extensions.yaml @@ -0,0 +1,49 @@ +- description: Simple GraphQL object query on author, where the request includes extensions (normal request). + url: /v1/graphql + headers: + X-Hasura-Role: admin + status: 200 + response: + data: + author: + - id: 1 + name: Author 1 + - id: 2 + name: Author 2 + query: + # https://graphql.org/learn/serving-over-http/#post-request + operationName: chooseThisOne + extensions: null + query: | + query chooseThisOne { + author { + id + name + } + } + +- description: Simple GraphQL object query on author, where the request includes persisted query extension. + url: /v1/graphql + headers: + X-Hasura-Role: admin + status: 200 + response: + errors: + - extensions: + path: $ + code: not-supported + message: Automatic Persisted Queries is not enabled + query: + # https://graphql.org/learn/serving-over-http/#post-request + operationName: chooseThisOne + extensions: + persistedQuery: + version: 1 + sha256Hash: randomhash + query: | + query chooseThisOne { + author { + id + name + } + } diff --git a/server/tests-py/test_graphql_queries.py b/server/tests-py/test_graphql_queries.py index 5fd1cc59aa55d..13a4c611326e3 100644 --- a/server/tests-py/test_graphql_queries.py +++ b/server/tests-py/test_graphql_queries.py @@ -180,6 +180,10 @@ def test_select_query_batching_with_one_error(self, hge_ctx, transport): def test_create_invalid_fkey_relationship(self, hge_ctx, transport): resp = hge_ctx.v1q_f(self.dir() + '/setup_invalid_fkey_relationship.yaml', expected_status_code = 400) assert resp['error'] == "Expecting object { table, columns }." + + def test_select_query_with_extensions(self, hge_ctx, transport): + transport = 'http' + check_query_f(hge_ctx, self.dir() + "/select_query_with_extensions.yaml", transport) @classmethod def dir(cls):