Skip to content

Commit e9e0c95

Browse files
committed
Add test for custom ExecutionContext (#6)
1 parent ea0c52a commit e9e0c95

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ a query language for APIs created by Facebook.
1313

1414
The current version 1.0.1 of GraphQL-core-next is up-to-date with GraphQL.js
1515
version 14.0.2. All parts of the API are covered by an extensive test suite of
16-
currently 1614 unit tests.
16+
currently 1615 unit tests.
1717

1818

1919
## Documentation

tests/execution/test_executor.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pytest import raises, mark
66

77
from graphql.error import GraphQLError
8-
from graphql.execution import execute
8+
from graphql.execution import execute, ExecutionContext
99
from graphql.language import parse, OperationDefinitionNode, FieldNode
1010
from graphql.type import (
1111
GraphQLSchema,
@@ -846,3 +846,23 @@ def custom_resolver(_source, info, **_args):
846846
{"foo": "foo"},
847847
None,
848848
)
849+
850+
def uses_a_custom_execution_context_class():
851+
query = parse("{ foo }")
852+
853+
schema = GraphQLSchema(
854+
GraphQLObjectType(
855+
"Query",
856+
{"foo": GraphQLField(GraphQLString, resolve=lambda *_args: "bar")},
857+
)
858+
)
859+
860+
class TestExecutionContext(ExecutionContext):
861+
def resolve_field(self, parent_type, source, field_nodes, path):
862+
result = super().resolve_field(parent_type, source, field_nodes, path)
863+
return result * 2
864+
865+
assert execute(schema, query, execution_context_class=TestExecutionContext) == (
866+
{"foo": "barbar"},
867+
None,
868+
)

0 commit comments

Comments
 (0)