context=request.headers) return mkJSONResp(res) handlers = MkHandlers({ '/hello': HelloWorldHandler, '/hello-graphql': HelloGraphQL, '/user-graphql': UserGraphQL, '/country-graphql': CountryGraphQL, '/character-iface-graphql': CharacterInterfaceGraphQL, '/iface-graphql-err-empty-field-list': InterfaceGraphQLErrEmptyFieldList, '/iface-graphql-err-unknown-iface': InterfaceGraphQLErrUnknownInterface, '/iface-graphql-err-missing-field': InterfaceGraphQLErrMissingField, '/iface-graphql-err-wrong-field-type': InterfaceGraphQLErrWrongFieldType, '/iface-graphql-err-missing-arg': InterfaceGraphQLErrMissingArg, '/iface-graphql-err-wrong-arg-type': InterfaceGraphQLErrWrongArgType, '/iface-graphql-err-extra-non-null-arg': InterfaceGraphQLErrExtraNonNullArg, '/union-graphql': UnionGraphQL, '/union-graphql-err-unknown-types': UnionGraphQLSchemaErrUnknownTypes, '/union-graphql-err-subtype-iface': UnionGraphQLSchemaErrSubTypeInterface, '/union-graphql-err-no-member-types': UnionGraphQLSchemaErrNoMemberTypes, '/union-graphql-err-wrapped-type': UnionGraphQLSchemaErrWrappedType, '/default-value-echo-graphql': EchoGraphQL, '/person-graphql': PersonGraphQL, '/header-graphql': HeaderTestGraphQL, '/auth-graphql': SampleAuthGraphQL, }) def create_server(host='127.0.0.1', port=5000): return WebServer((host, port), handlers)
{}).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'}) handlers = MkHandlers({ '/hello': HelloWorldHandler, '/hello-graphql': HelloGraphQL, '/user-graphql': UserGraphQL, '/country-graphql': CountryGraphQL, '/default-value-echo-graphql': EchoGraphQL, '/person-graphql': PersonGraphQL }) def create_server(host='127.0.0.1', port=5000): return WebServer((host, port), handlers) def stop_server(server): server.shutdown() server.server_close() if __name__ == '__main__':
return Country("India") country_schema = graphene.Schema(query=CountryQuery) class CountryGraphQL(RequestHandler): def get(self, req): return Response(HTTPStatus.METHOD_NOT_ALLOWED) def post(self, req): if not req.json: return Response(HTTPStatus.BAD_REQUEST) res = country_schema.execute(req.json['query']) return mkJSONResp(res) handlers = MkHandlers({ '/hello': HelloWorldHandler, '/hello-graphql': HelloGraphQL, '/user-graphql': UserGraphQL, '/country-graphql': CountryGraphQL, }) def create_server(host='127.0.0.1', port=5000): return WebServer((host, port), handlers) def stop_server(server): server.shutdown() server.server_close() if __name__ == '__main__': s = create_server() s.serve_forever()
state['cache-control'] += 1 return resp class StateHandler(RequestHandler): def post(self, request): return Response(HTTPStatus.METHOD_NOT_ALLOWED) def get(self, request): resp = mkJSONResp(state) return resp handlers = MkHandlers({ # sending query string: `?field=smaxage`, will return Cache-Control with s-maxage, else with max-age # sending query string: `error=true` will respond with invalid header value '/jwk-cache-control': JwkCacheControlHandler, # sending query string: `error=true` will respond with invalid header value '/jwk-expires': JwkExpiresHandler, # API so that testing can be done '/state': StateHandler }) def create_server(host='127.0.0.1', port=5001): return WebServer((host, port), handlers) def stop_server(server): server.shutdown() server.server_close() # if you want to run this module to emulate a JWK server during development if __name__ == '__main__': s = create_server(port=5001)
if 'cookie' in headers and headers['cookie']: res = {'x-hasura-role': 'admin'} return Response(HTTPStatus.OK, res) return Response(HTTPStatus.UNAUTHORIZED) def post(self, request): headers = {k.lower(): v for k, v in request.json['headers'].items()} print(headers) if 'cookie' in headers and headers['cookie']: res = {'x-hasura-role': 'admin'} return Response(HTTPStatus.OK, res) return Response(HTTPStatus.UNAUTHORIZED) handlers = MkHandlers({ '/auth': CookieAuth, }) def create_server(host='127.0.0.1', port=9876): return WebServer((host, port), handlers) def stop_server(server): server.shutdown() server.server_close() if __name__ == '__main__': s = create_server(host='0.0.0.0') s.serve_forever()