Skip to content

Commit

Permalink
Add missing call to withConstructorFn in live queries (fix hasura#3239)
Browse files Browse the repository at this point in the history
  • Loading branch information
lexi-lambda committed Jan 18, 2020
1 parent 1fda8bf commit 99c0bde
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 25 deletions.
6 changes: 4 additions & 2 deletions server/src-lib/Hasura/GraphQL/Execute/LiveQuery/Plan.hs
Expand Up @@ -119,11 +119,13 @@ resolveMultiplexedValue = \case
GR.UVSQL sqlExp -> pure sqlExp
GR.UVSession -> pure $ fromResVars (PGTypeScalar PGJSON) ["session"]
where
fromResVars ty jPath =
flip S.SETyAnn (S.mkTypeAnn ty) $ S.SEOpApp (S.SQLOp "#>>")
fromResVars pgType jPath = addTypeAnnotation pgType $ S.SEOpApp (S.SQLOp "#>>")
[ S.SEQIden $ S.QIden (S.QualIden $ Iden "_subs") (Iden "result_vars")
, S.SEArray $ map S.SELit jPath
]
addTypeAnnotation pgType = flip S.SETyAnn (S.mkTypeAnn pgType) . case pgType of
PGTypeScalar scalarType -> withConstructorFn scalarType
PGTypeArray _ -> id

newtype CohortId = CohortId { unCohortId :: UUID }
deriving (Show, Eq, Hashable, J.ToJSON, Q.FromCol)
Expand Down
Expand Up @@ -7,7 +7,7 @@ response:
- name: New York
query:
query: |
{
query {
geog_table(where: {
geog_col: {
_cast: {
Expand Down
Expand Up @@ -8,7 +8,7 @@ response:
- name: Paris
query:
query: |
{
query {
geog_as_geom_table(where: {
geom_col: {
_cast: {
Expand Down
Expand Up @@ -9,7 +9,7 @@ response:
message: 'field "integer" not found in type: ''geography_cast_exp'''
query:
query: |
{
query {
geog_table(where: {geog_col: {_cast: {integer: {_eq: 0}}}}) {
name
}
Expand Down
2 changes: 1 addition & 1 deletion server/tests-py/test_graphql_queries.py
Expand Up @@ -371,7 +371,7 @@ def test_jsonb_has_keys_all_touchscreen_ram(self, hge_ctx, transport):
def dir(cls):
return 'queries/graphql_query/boolexp/jsonb'

@pytest.mark.parametrize("transport", ['http', 'websocket'])
@pytest.mark.parametrize("transport", ['http', 'websocket', 'subscription'])
class TestGraphQLQueryBoolExpPostGIS(DefaultTestSelectQueries):

def test_query_using_point(self, hge_ctx, transport):
Expand Down
48 changes: 29 additions & 19 deletions server/tests-py/validate.py
Expand Up @@ -12,6 +12,7 @@
import json
import jsondiff
import jwt
import queue
import random
import time
import warnings
Expand Down Expand Up @@ -180,27 +181,31 @@ def check_query(hge_ctx, conf, transport='http', add_auth=True):
test_forbidden_when_admin_secret_reqd(hge_ctx, conf)
headers['X-Hasura-Admin-Secret'] = hge_ctx.hge_key

assert transport in ['websocket', 'http'], "Unknown transport type " + transport
if transport == 'websocket':
assert 'response' in conf
assert conf['url'].endswith('/graphql')
print('running on websocket')
return validate_gql_ws_q(
hge_ctx,
conf['url'],
conf['query'],
headers,
conf['response'],
True
)
elif transport == 'http':
assert transport in ['http', 'websocket', 'subscription'], "Unknown transport type " + transport
if transport == 'http':
print('running on http')
return validate_http_anyq(hge_ctx, conf['url'], conf['query'], headers,
conf['status'], conf.get('response'))
elif transport == 'websocket':
print('running on websocket')
return validate_gql_ws_q(hge_ctx, conf, headers, retry=True)
elif transport == 'subscription':
print('running via subscription')
return validate_gql_ws_q(hge_ctx, conf, headers, retry=True, via_subscription=True)


def validate_gql_ws_q(hge_ctx, conf, headers, retry=False, via_subscription=False):
assert 'response' in conf
assert conf['url'].endswith('/graphql')
endpoint = conf['url']
query = conf['query']
exp_http_response = conf['response']

if via_subscription:
query_text = query['query']
assert query_text.startswith('query '), query_text
query['query'] = 'subscription' + query_text[len('query'):]

def validate_gql_ws_q(hge_ctx, endpoint, query, headers, exp_http_response, retry=False):
if endpoint == '/v1alpha1/graphql':
ws_client = GQLWsClient(hge_ctx, '/v1alpha1/graphql')
else:
Expand All @@ -209,7 +214,7 @@ def validate_gql_ws_q(hge_ctx, endpoint, query, headers, exp_http_response, retr
if not headers or len(headers) == 0:
ws_client.init({})

query_resp = ws_client.send_query(query, headers=headers, timeout=15)
query_resp = ws_client.send_query(query, query_id='hge_test', headers=headers, timeout=15)
resp = next(query_resp)
print('websocket resp: ', resp)

Expand All @@ -226,10 +231,15 @@ def validate_gql_ws_q(hge_ctx, endpoint, query, headers, exp_http_response, retr
assert resp['type'] in ['data', 'error'], resp
else:
assert resp['type'] == 'data', resp

assert 'payload' in resp, resp
resp_done = next(query_resp)
assert resp_done['type'] == 'complete'

if via_subscription:
ws_client.send({ 'id': 'hge_test', 'type': 'stop' })
with pytest.raises(queue.Empty):
ws_client.get_ws_event(0)
else:
resp_done = next(query_resp)
assert resp_done['type'] == 'complete'

return assert_graphql_resp_expected(resp['payload'], exp_http_response, query)

Expand Down

0 comments on commit 99c0bde

Please sign in to comment.