def test_v1alpha1_ws_start_error(self, hge_ctx): ws_client = GQLWsClient(hge_ctx, '/v1alpha1/graphql') query = {'query': '{ author { name } }'} frame = {'id': '1', 'type': 'start', 'payload': query} ws_client.ws_active_query_ids.add('1') ws_client.send(frame) resp = ws_client.get_ws_query_event('1', 10) print(resp) assert 'type' in resp assert resp['type'] == 'error' assert 'payload' in resp assert resp['payload'] == { 'path': '$', 'error': 'start received before the connection is initialised', 'code': 'start-failed' }
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 # make the query into a subscription and add the # _multiple_subscriptions directive that enables having more # than 1 root field in a subscription query['query'] = 'subscription' + query_text[len('query'):].replace( "{", " @_multiple_top_level_fields {", 1) if endpoint == '/v1alpha1/graphql': ws_client = GQLWsClient(hge_ctx, '/v1alpha1/graphql') else: ws_client = hge_ctx.ws_client print(ws_client.ws_url) if not headers or len(headers) == 0: ws_client.init({}) query_resp = ws_client.send_query(query, query_id='hge_test', headers=headers, timeout=15) resp = next(query_resp) print('websocket resp: ', resp) if resp.get('type') == 'complete': if retry: #Got query complete before payload. Retry once more print( "Got query complete before getting query response payload. Retrying" ) ws_client.recreate_conn() return validate_gql_ws_q(hge_ctx, query, headers, exp_http_response, False) else: assert resp['type'] in ['data', 'error'], resp if 'errors' in exp_http_response or 'error' in exp_http_response: assert resp['type'] in ['data', 'error'], resp else: assert resp['type'] == 'data', resp assert 'payload' in resp, resp 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, skip_if_err_msg=hge_ctx.avoid_err_msg_checks)