Skip to content

Commit

Permalink
Add test for custom ExecutionContext (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Sep 19, 2018
1 parent ea0c52a commit e9e0c95
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ a query language for APIs created by Facebook.

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


## Documentation
Expand Down
22 changes: 21 additions & 1 deletion tests/execution/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pytest import raises, mark

from graphql.error import GraphQLError
from graphql.execution import execute
from graphql.execution import execute, ExecutionContext
from graphql.language import parse, OperationDefinitionNode, FieldNode
from graphql.type import (
GraphQLSchema,
Expand Down Expand Up @@ -846,3 +846,23 @@ def custom_resolver(_source, info, **_args):
{"foo": "foo"},
None,
)

def uses_a_custom_execution_context_class():
query = parse("{ foo }")

schema = GraphQLSchema(
GraphQLObjectType(
"Query",
{"foo": GraphQLField(GraphQLString, resolve=lambda *_args: "bar")},
)
)

class TestExecutionContext(ExecutionContext):
def resolve_field(self, parent_type, source, field_nodes, path):
result = super().resolve_field(parent_type, source, field_nodes, path)
return result * 2

assert execute(schema, query, execution_context_class=TestExecutionContext) == (
{"foo": "barbar"},
None,
)

0 comments on commit e9e0c95

Please sign in to comment.