Skip to content

Commit a8affc2

Browse files
fix intermittent errors occur when query actions used with variables (hasura#4527)
* don't add query actions to the plan cache Co-authored-by: rakeshkky <12475069+rakeshkky@users.noreply.github.com>
1 parent b51a8ec commit a8affc2

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

‎server/src-lib/Hasura/GraphQL/Resolve.hs‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,16 @@ queryFldToPGAST fld actionExecuter = do
119119
QCAsyncActionFetch ctx ->
120120
QRFActionSelect <$> RA.resolveAsyncActionQuery userInfo ctx fld
121121
QCAction ctx -> do
122-
case jsonAggType of
123-
DS.JASMultipleRows -> QRFActionExecuteList
124-
DS.JASSingleObject -> QRFActionExecuteObject
125-
<$> actionExecuter (RA.resolveActionQuery fld ctx (userVars userInfo))
122+
-- query actions should not be marked reusable because we aren't
123+
-- capturing the variable value in the state as re-usable variables.
124+
-- The variables captured in non-action queries are used to generate
125+
-- an SQL query, but in case of query actions it's converted into JSON
126+
-- and included in the action's webhook payload.
127+
markNotReusable
128+
let f = case jsonAggType of
129+
DS.JASMultipleRows -> QRFActionExecuteList
130+
DS.JASSingleObject -> QRFActionExecuteObject
131+
f <$> actionExecuter (RA.resolveActionQuery fld ctx (userVars userInfo))
126132
where
127133
outputType = _saecOutputType ctx
128134
jsonAggType = RA.mkJsonAggSelect outputType

‎server/tests-py/queries/actions/sync/get_user_by_email_success.yaml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ url: /v1/graphql
33
status: 200
44
query:
55
query: |
6-
query {
7-
get_user_by_email(email: "clarke@gmail.com"){
6+
query ($email: String!){
7+
get_user_by_email(email: $email){
88
id
99
user {
1010
name
@@ -13,6 +13,8 @@ query:
1313
}
1414
}
1515
16+
variables:
17+
email: clarke@gmail.com
1618

1719
response:
1820
data:

‎server/tests-py/test_actions.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,23 @@ def test_query_action_success_output_list(self, hge_ctx):
117117
assert code == 200,resp
118118
check_query_f(hge_ctx, self.dir() + '/get_users_by_email_success.yaml')
119119

120+
# This test is to make sure that query actions work well with variables.
121+
# Earlier the HGE used to add the query action to the plan cache, which
122+
# results in interrmittent validation errors, like:
123+
# {
124+
# "errors": [
125+
# {
126+
# "extensions": {
127+
# "path": "$.variableValues",
128+
# "code": "validation-failed"
129+
# },
130+
# "message": "unexpected variables: email"
131+
# }
132+
# ]
133+
# }
134+
def test_query_action_should_not_throw_validation_error(self, hge_ctx):
135+
for _ in range(25):
136+
self.test_query_action_success_output_object(hge_ctx)
120137

121138
def mk_headers_with_secret(hge_ctx, headers={}):
122139
admin_secret = hge_ctx.hge_key

0 commit comments

Comments
 (0)