-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Graphene3 and update lint with black (#72)
Co-authored-by: Sebastian Hernandez <[email protected]>
- Loading branch information
Showing
10 changed files
with
128 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,73 @@ | ||
from graphql import ( | ||
ResolveInfo, | ||
GraphQLResolveInfo, | ||
Source, | ||
Undefined, | ||
parse, | ||
) | ||
from graphql.execution.base import ( | ||
from graphql.execution.execute import ( | ||
ExecutionContext, | ||
collect_fields, | ||
get_field_def, | ||
get_operation_root_type, | ||
) | ||
from graphql.pyutils.default_ordered_dict import DefaultOrderedDict | ||
from graphql.utilities import get_operation_root_type | ||
from collections import defaultdict | ||
|
||
from graphql.pyutils import Path | ||
|
||
|
||
def create_execution_context(schema, request_string, variables=None): | ||
source = Source(request_string, "GraphQL request") | ||
document_ast = parse(source) | ||
return ExecutionContext( | ||
return ExecutionContext.build( | ||
schema, | ||
document_ast, | ||
root_value=None, | ||
context_value=None, | ||
variable_values=variables, | ||
raw_variable_values=variables, | ||
operation_name=None, | ||
executor=None, | ||
middleware=None, | ||
allow_subscriptions=False, | ||
) | ||
|
||
|
||
def get_field_asts_from_execution_context(exe_context): | ||
fields = collect_fields( | ||
exe_context, | ||
fields = exe_context.collect_fields( | ||
type, | ||
exe_context.operation.selection_set, | ||
DefaultOrderedDict(list), | ||
defaultdict(list), | ||
set(), | ||
) | ||
# field_asts = next(iter(fields.values())) | ||
field_asts = tuple(fields.values())[0] | ||
return field_asts | ||
|
||
|
||
def create_resolve_info(schema, request_string, variables=None): | ||
def create_resolve_info(schema, request_string, variables=None, return_type=None): | ||
exe_context = create_execution_context(schema, request_string, variables) | ||
parent_type = get_operation_root_type(schema, exe_context.operation) | ||
field_asts = get_field_asts_from_execution_context(exe_context) | ||
|
||
field_ast = field_asts[0] | ||
field_name = field_ast.name.value | ||
|
||
field_def = get_field_def(schema, parent_type, field_name) | ||
if not field_def: | ||
return Undefined | ||
return_type = field_def.type | ||
if return_type is None: | ||
field_def = get_field_def(schema, parent_type, field_name) | ||
if not field_def: | ||
return Undefined | ||
return_type = field_def.type | ||
|
||
# The resolve function's optional third argument is a context value that | ||
# is provided to every resolve function within an execution. It is commonly | ||
# used to represent an authenticated user, or request-specific caches. | ||
context = exe_context.context_value | ||
return ResolveInfo( | ||
return GraphQLResolveInfo( | ||
field_name, | ||
field_asts, | ||
return_type, | ||
parent_type, | ||
schema=schema, | ||
fragments=exe_context.fragments, | ||
root_value=exe_context.root_value, | ||
operation=exe_context.operation, | ||
variable_values=exe_context.variable_values, | ||
context=context, | ||
Path(None, 0, None), | ||
schema, | ||
exe_context.fragments, | ||
exe_context.root_value, | ||
exe_context.operation, | ||
exe_context.variable_values, | ||
exe_context.context_value, | ||
exe_context.is_awaitable, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.