Skip to content

Fix execution with return_promise=True #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions graphql_server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import json
from collections import namedtuple, MutableMapping
from collections import MutableMapping, namedtuple

import six

from graphql import Source, execute, parse, validate
from graphql.error import format_error as format_graphql_error
from graphql.error import GraphQLError
from graphql.execution import ExecutionResult
from graphql.utils.get_operation_ast import get_operation_ast
from promise import promisify

from .error import HttpQueryError

Expand Down Expand Up @@ -126,7 +128,7 @@ def get_graphql_params(data, query_data):

def get_response(schema, params, catch=None, allow_only_query=False, **kwargs):
try:
execution_result = execute_graphql_request(
execution_result = execute_graphql(
schema,
params,
allow_only_query,
Expand Down Expand Up @@ -159,6 +161,19 @@ def format_execution_result(execution_result, format_error):
return GraphQLResponse(response, status_code)


def execute_graphql(*args, **kwargs):
return_promise = kwargs.get('return_promise', False)
if return_promise:
return execute_graphql_request_as_promise(*args, **kwargs)
else:
return execute_graphql_request(*args, **kwargs)


@promisify
def execute_graphql_request_as_promise(*args, **kwargs):
return execute_graphql_request(*args, **kwargs)


def execute_graphql_request(schema, params, allow_only_query=False, **kwargs):
if not params.query:
raise HttpQueryError(400, 'Must provide query string.')
Expand Down