def post(self, req): if not req.json: return Response(HTTPStatus.BAD_REQUEST) res = character_interface_schema.execute(req.json['query']) respDict = res.to_dict() typesList = respDict.get('data',{}).get('__schema',{}).get('types',None) if typesList is not None: for t in typesList: #Remove id field from Droid if t['kind'] == 'OBJECT' and t['name'] == 'Droid': for f in t['fields'].copy(): if f['name'] == 'id': t['fields'].remove(f) return Response(HTTPStatus.OK, respDict, {'Content-Type': 'application/json'})
def post(self, req): if not req.json: return Response(HTTPStatus.BAD_REQUEST) res = character_interface_schema.execute(req.json['query']) respDict = res.to_dict() typesList = respDict.get('data', {}).get('__schema', {}).get('types', None) if typesList is not None: for t in typesList: if t['kind'] == 'INTERFACE': for f in t['fields']: if f['name'] == 'id': f['args'].append(ifaceArg) return Response(HTTPStatus.OK, respDict, {'Content-Type': 'application/json'})
def post(self, request): if not request.json: return Response(HTTPStatus.BAD_REQUEST) res = hello_schema.execute(request.json['query']) respDict = res.to_dict() # Return the result as it is, when we send an introspection query if respDict.get('data', {}).get('__schema', {}): return mkJSONResp(res) # Edit the result to contain, the 'request payload' as part of the response. # We can then use this to assert the request payload with the expected response. else: respDict.get('data', {})['hello'] = request.json return Response(HTTPStatus.OK, res.to_dict(), {'Content-Type': 'application/json'})
def get(self, request): headers = {k.lower(): v for k, v in request.headers.items()} print(headers) cookieHdrs = [] if 'cookie' in headers and headers['cookie']: res = {'x-hasura-role': 'admin'} for k, v in headers.items(): if 'response-set-cookie' in k: hdr = ('Set-Cookie', v) cookieHdrs.append(hdr) return Response(HTTPStatus.OK, res, cookieHdrs) return Response(HTTPStatus.UNAUTHORIZED)
def post(self, req): if not req.json: return Response(HTTPStatus.BAD_REQUEST) res = echo_schema.execute(req.json['query']) respDict = res.to_dict() typesList = respDict.get('data', {}).get('__schema', {}).get('types', None) if typesList is not None: for t in filter(lambda ty: ty['name'] == 'EchoQuery', typesList): for f in filter(lambda fld: fld['name'] == 'echo', t['fields']): for a in filter(lambda arg: arg['name'] == 'enumInput', f['args']): a['defaultValue'] = 'RED' return Response(HTTPStatus.OK, respDict, {'Content-Type': 'application/json'})
def post(self, req): if not req.json: return Response(HTTPStatus.BAD_REQUEST) res = echo_schema.execute(req.json['query']) resp_dict = res.to_dict() types_list = resp_dict.get('data', {}).get('__schema', {}).get('types', None) #Hack around enum default_value serialization issue: https://github.com/graphql-python/graphql-core/issues/166 if types_list is not None: for t in filter(lambda ty: ty['name'] == 'EchoQuery', types_list): for f in filter(lambda fld: fld['name'] == 'echo', t['fields']): for a in filter(lambda arg: arg['name'] == 'enumInput', f['args']): a['defaultValue'] = 'RED' return Response(HTTPStatus.OK, resp_dict, {'Content-Type': 'application/json'})
def post(self, request): if not request.json: return Response(HTTPStatus.BAD_REQUEST) res = hello_schema.execute(request.json['query']) resp = mkJSONResp(res) resp.headers['Set-Cookie'] = 'abcd' resp.headers['Custom-Header'] = 'custom-value' return resp
def post(self, req): if not req.json: return Response(HTTPStatus.BAD_REQUEST) res = union_schema.execute(req.json['query']) respDict = res.to_dict() typesList = respDict.get('data',{}).get('__schema',{}).get('types',None) if typesList is not None: for t in typesList: if t['kind'] == 'UNION': for i, p in enumerate(t['possibleTypes']): t['possibleTypes'][i] = { "kind": "NON_NULL", "name": None, "ofType": p } return Response(HTTPStatus.OK, respDict, {'Content-Type': 'application/json'})
def post(self, request): if not request.json: return Response(HTTPStatus.BAD_REQUEST) res = hello_schema.execute(request.json['query']) extensions = { 'extensions': { 'message': 'an extra field in response object' } } return mkJSONResp(res, extensions)
def post(self, req): if not req.json: return Response(HTTPStatus.BAD_REQUEST) res = character_interface_schema.execute(req.json['query']) respDict = res.to_dict() objArg = copy.deepcopy(ifaceArg) objArg['type']['ofType']['name'] = 'String' typesList = respDict.get('data',{}).get('__schema',{}).get('types',None) if typesList is not None: for t in filter(lambda ty : ty['kind'] == 'INTERFACE', typesList): for f in filter(lambda fld: fld['name'] == 'id', t['fields']): f['args'].append(ifaceArg) for t in filter(lambda ty: ty['name'] in ['Droid','Human'], typesList): for f in filter(lambda fld: fld['name'] == 'id', t['fields']): f['args'].append(ifaceArg if t['name'] == 'Droid' else objArg) return Response(HTTPStatus.OK, respDict, {'Content-Type': 'application/json'})
def mkJSONResp(graphql_result, extensions={}): return Response(HTTPStatus.OK, { **graphql_result.to_dict(), **extensions }, {'Content-Type': 'application/json'})
def post(self, req): if not req.json: return Response(HTTPStatus.BAD_REQUEST) res = union_schema.execute(req.json['query']) return mkJSONResp(res)
def get(self, request): return Response(HTTPStatus.OK, 'hello world')
def mkJSONResp(graphql_result): return Response(HTTPStatus.OK, graphql_result.to_dict(), {'Content-Type': 'application/json'})
def post(self, request): if not request.json: return Response(HTTPStatus.BAD_REQUEST) res = messages_schema.execute(request.json['query']) return mkJSONResp(res)
def post(self, request): state['cache-control'] = 0 state['expires'] = 0 return Response(HTTPStatus.OK)
def get(self, request): return Response(HTTPStatus.METHOD_NOT_ALLOWED)
def mkJSONResp(json_result): return Response(HTTPStatus.OK, json_result, {'Content-Type': 'application/json'})
def post(self, request): if not request.json: return Response(HTTPStatus.BAD_REQUEST) res = header_test_schema.execute(request.json['query'], context=request.headers) return mkJSONResp(res)
def post(self, req): if not req.json: return Response(HTTPStatus.BAD_REQUEST) res = character_interface_schema.execute( req.json['query'], variable_values=req.json.get('variables')) return mkJSONResp(res)