from hiku.graph import Graph, Root, Field GRAPH = Graph([ Root([ Field('now', None, lambda _: [datetime.now().isoformat()]), ]), ]) # test from hiku.engine import Engine from hiku.result import denormalize from hiku.executors.sync import SyncExecutor from hiku.readers.simple import read hiku_engine = Engine(SyncExecutor()) def execute(graph, query_string): query = read(query_string) result = hiku_engine.execute(graph, query) return denormalize(graph, result, query) from tests.base import patch, Mock _NOW = datetime(2015, 10, 21, 7, 28) @patch('{}.datetime'.format(__name__)) def test(dt):
def execute(graph, query_, ctx=None): engine = Engine(SyncExecutor()) return engine.execute(graph, query_, ctx=ctx)
data_types=DATA_TYPES) MUTATION_GRAPH = Graph(QUERY_GRAPH.nodes + [ Root([ Field('action', Boolean, action_func, options=[Option('data', TypeRef['Data'])]), ]), ], data_types=DATA_TYPES) app = Flask(__name__) graphql_endpoint = GraphQLEndpoint( Engine(SyncExecutor()), QUERY_GRAPH, MUTATION_GRAPH, ) @app.route('/graphql', methods={'POST'}) def handle_graphql(): data = request.get_json() result = graphql_endpoint.dispatch(data) return jsonify(result) def main(): logging.basicConfig() app.run(port=5000)