Skip to content

Commit

Permalink
server: fix condition to classify requests to Apollo persisted querie…
Browse files Browse the repository at this point in the history
…s (cherry-pick)

Cherry picks PR: hasura/graphql-engine-mono#10514

PR-URL: hasura/graphql-engine-mono#10536
GitOrigin-RevId: b60c7a30766bcbfab09db9989c131712a46fc6d7
  • Loading branch information
pranshi06 authored and hasura-bot committed Dec 6, 2023
1 parent 1b1239b commit 18d3035
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
4 changes: 2 additions & 2 deletions server/src-lib/Hasura/Server/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
4 changes: 4 additions & 0 deletions server/tests-py/test_graphql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 18d3035

Please sign in to comment.