Skip to content

Commit f67f813

Browse files
committed
Improved testing cases in executor
1 parent fd0fbf6 commit f67f813

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

graphql/execution/querybuilder/tests/test_executor.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from ....language import ast
55
from ....type import (GraphQLEnumType, GraphQLInterfaceType, GraphQLList,
6-
GraphQLNonNull, GraphQLObjectType, GraphQLScalarType,
6+
GraphQLNonNull, GraphQLObjectType, GraphQLScalarType, GraphQLBoolean,
77
GraphQLSchema, GraphQLUnionType, GraphQLString, GraphQLInt, GraphQLField)
88
from ..resolver import type_resolver
99
from ..fragment import Fragment
@@ -45,3 +45,72 @@ def test_fragment_resolver_abstract(benchmark):
4545
'name': 'name:'+str(x)
4646
} for x in all_slots]
4747
}
48+
49+
50+
def test_fragment_resolver_context():
51+
Query = GraphQLObjectType('Query', fields={
52+
'context': GraphQLField(GraphQLString, resolver=lambda root, args, context, info: context),
53+
'same_schema': GraphQLField(GraphQLBoolean, resolver=lambda root, args, context, info: info.schema == schema)
54+
})
55+
56+
document_ast = parse('''query {
57+
context
58+
same_schema
59+
}''')
60+
# node_fragment = Fragment(type=Node, field_asts=node_field_asts)
61+
schema = GraphQLSchema(query=Query)
62+
# partial_execute = partial(execute, schema, document_ast, context_value="1")
63+
# resolved = benchmark(partial_execute)
64+
resolved = execute(schema, document_ast, context_value="1")
65+
assert not resolved.errors
66+
assert resolved.data == {
67+
'context': '1',
68+
'same_schema': True,
69+
}
70+
71+
72+
def test_fragment_resolver_fails():
73+
def raise_resolver(*args, **kwargs):
74+
raise Exception("My exception")
75+
76+
def succeeds_resolver(*args, **kwargs):
77+
return True
78+
79+
Query = GraphQLObjectType('Query', fields={
80+
'fails': GraphQLField(GraphQLString, resolver=raise_resolver),
81+
'succeeds': GraphQLField(GraphQLBoolean, resolver=succeeds_resolver)
82+
})
83+
84+
document_ast = parse('''query {
85+
fails
86+
succeeds
87+
}''')
88+
# node_fragment = Fragment(type=Node, field_asts=node_field_asts)
89+
schema = GraphQLSchema(query=Query)
90+
# partial_execute = partial(execute, schema, document_ast, context_value="1")
91+
# resolved = benchmark(partial_execute)
92+
resolved = execute(schema, document_ast, context_value="1")
93+
assert len(resolved.errors) == 1
94+
assert resolved.data == {
95+
'fails': None,
96+
'succeeds': True,
97+
}
98+
99+
100+
def test_fragment_resolver_resolves_all_list():
101+
Query = GraphQLObjectType('Query', fields={
102+
'ints': GraphQLField(GraphQLList(GraphQLNonNull(GraphQLInt)), resolver=lambda *args: [1, "2", "NaN"]),
103+
})
104+
105+
document_ast = parse('''query {
106+
ints
107+
}''')
108+
# node_fragment = Fragment(type=Node, field_asts=node_field_asts)
109+
schema = GraphQLSchema(query=Query)
110+
# partial_execute = partial(execute, schema, document_ast, context_value="1")
111+
# resolved = benchmark(partial_execute)
112+
resolved = execute(schema, document_ast, context_value="1")
113+
assert len(resolved.errors) == 1
114+
assert resolved.data == {
115+
'ints': [1, 2, None]
116+
}

0 commit comments

Comments
 (0)