Skip to content

Commit 3bc1096

Browse files
committed
test: Switch to using keyword args to graphql/execute
Though it's questionable if this always makes sense in Python. But some of the test may become a bit more readable. Replicates graphql/graphql-js@9063ade
1 parent 1ff3e96 commit 3bc1096

13 files changed

+237
-186
lines changed

src/graphql/utilities/introspection_from_schema.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ def introspection_from_schema(
2222
This is the inverse of build_client_schema. The primary use case is outside of the
2323
server context, for instance when doing schema comparisons.
2424
"""
25-
query_ast = parse(get_introspection_query(descriptions))
25+
document = parse(get_introspection_query(descriptions))
2626

2727
from ..execution.execute import execute, ExecutionResult
2828

29-
result = execute(schema, query_ast)
29+
result = execute(schema, document)
3030
if not isinstance(result, ExecutionResult):
3131
raise RuntimeError("Introspection cannot be executed")
3232
if result.errors or not result.data:

tests/benchmarks/test_introspection_from_schema.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
def test_execute_introspection_query(benchmark, big_schema_sdl): # noqa: F811
99
schema = build_schema(big_schema_sdl, assume_valid=True)
10-
query = parse(get_introspection_query())
11-
result = benchmark(lambda: execute(schema, query))
10+
document = parse(get_introspection_query())
11+
result = benchmark(lambda: execute(schema=schema, document=document))
1212
assert result.errors is None

tests/execution/test_abstract_async.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async def is_type_of_used_to_resolve_runtime_type_for_interface():
9696
types=[CatType, DogType],
9797
)
9898

99-
query = """
99+
source = """
100100
{
101101
pets {
102102
name
@@ -110,7 +110,7 @@ async def is_type_of_used_to_resolve_runtime_type_for_interface():
110110
}
111111
"""
112112

113-
result = await graphql(schema, query)
113+
result = await graphql(schema=schema, source=source)
114114
assert result == (
115115
{
116116
"pets": [
@@ -161,7 +161,7 @@ async def is_type_of_with_async_error():
161161
types=[CatType, DogType],
162162
)
163163

164-
query = """
164+
source = """
165165
{
166166
pets {
167167
name
@@ -175,7 +175,7 @@ async def is_type_of_with_async_error():
175175
}
176176
"""
177177

178-
result = await graphql(schema, query)
178+
result = await graphql(schema=schema, source=source)
179179
# Note: we get two errors, because first all types are resolved
180180
# and only then they are checked sequentially
181181
assert result.data == {"pets": [None, None]}
@@ -229,7 +229,7 @@ async def is_type_of_used_to_resolve_runtime_type_for_union():
229229
)
230230
)
231231

232-
query = """
232+
source = """
233233
{
234234
pets {
235235
... on Dog {
@@ -244,7 +244,7 @@ async def is_type_of_used_to_resolve_runtime_type_for_union():
244244
}
245245
"""
246246

247-
result = await graphql(schema, query)
247+
result = await graphql(schema=schema, source=source)
248248
assert result == (
249249
{
250250
"pets": [
@@ -306,7 +306,7 @@ async def resolve_type_on_interface_yields_useful_error():
306306
types=[CatType, DogType],
307307
)
308308

309-
query = """
309+
source = """
310310
{
311311
pets {
312312
name
@@ -320,7 +320,7 @@ async def resolve_type_on_interface_yields_useful_error():
320320
}
321321
"""
322322

323-
result = await graphql(schema, query)
323+
result = await graphql(schema=schema, source=source)
324324
assert result.data == {
325325
"pets": [
326326
{"name": "Odie", "woofs": True},
@@ -382,7 +382,7 @@ async def resolve_type_on_union_yields_useful_error():
382382
)
383383
)
384384

385-
query = """
385+
source = """
386386
{
387387
pets {
388388
... on Dog {
@@ -397,7 +397,7 @@ async def resolve_type_on_union_yields_useful_error():
397397
}
398398
"""
399399

400-
result = await graphql(schema, query)
400+
result = await graphql(schema=schema, source=source)
401401
assert result.data == {
402402
"pets": [
403403
{"name": "Odie", "woofs": True},
@@ -454,7 +454,7 @@ async def resolve_type_allows_resolving_with_type_name():
454454
types=[CatType, DogType],
455455
)
456456

457-
query = """{
457+
source = """{
458458
pets {
459459
name
460460
... on Dog {
@@ -466,7 +466,7 @@ async def resolve_type_allows_resolving_with_type_name():
466466
}
467467
}"""
468468

469-
result = await graphql(schema, query)
469+
result = await graphql(schema=schema, source=source)
470470
assert result == (
471471
{
472472
"pets": [
@@ -514,7 +514,7 @@ async def resolve_type_can_be_caught():
514514
types=[CatType, DogType],
515515
)
516516

517-
query = """{
517+
source = """{
518518
pets {
519519
name
520520
... on Dog {
@@ -526,7 +526,7 @@ async def resolve_type_can_be_caught():
526526
}
527527
}"""
528528

529-
result = await graphql(schema, query)
529+
result = await graphql(schema=schema, source=source)
530530
assert result == (
531531
{"pets": [None, None]},
532532
[

tests/execution/test_lists.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ def get_response(test_type, test_data):
3737
},
3838
)
3939

40-
schema = GraphQLSchema(data_type)
41-
42-
ast = parse("{ nest { test } }")
43-
44-
return execute(schema, ast, data)
40+
return execute(
41+
schema=GraphQLSchema(data_type),
42+
document=parse("{ nest { test } }"),
43+
context_value=data,
44+
)
4545

4646

4747
def check_response(response, expected):

tests/execution/test_mutations.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ async def promise_and_fail_to_change_the_number(self, newNumber: int):
9393
def describe_execute_handles_mutation_execution_ordering():
9494
@mark.asyncio
9595
async def evaluates_mutations_serially():
96-
doc = """
96+
document = parse(
97+
"""
9798
mutation M {
9899
first: immediatelyChangeTheNumber(newNumber: 1) {
99100
theNumber
@@ -112,8 +113,12 @@ async def evaluates_mutations_serially():
112113
}
113114
}
114115
"""
116+
)
115117

116-
awaitable_result = execute(schema, parse(doc), Root(6))
118+
root_value = Root(6)
119+
awaitable_result = execute(
120+
schema=schema, document=document, root_value=root_value
121+
)
117122
assert isinstance(awaitable_result, Awaitable)
118123
mutation_result = await awaitable_result
119124

@@ -130,7 +135,8 @@ async def evaluates_mutations_serially():
130135

131136
@mark.asyncio
132137
async def evaluates_mutations_correctly_in_presence_of_a_failed_mutation():
133-
doc = """
138+
document = parse(
139+
"""
134140
mutation M {
135141
first: immediatelyChangeTheNumber(newNumber: 1) {
136142
theNumber
@@ -152,8 +158,12 @@ async def evaluates_mutations_correctly_in_presence_of_a_failed_mutation():
152158
}
153159
}
154160
"""
161+
)
155162

156-
awaitable_result = execute(schema, parse(doc), Root(6))
163+
root_value = Root(6)
164+
awaitable_result = execute(
165+
schema=schema, document=document, root_value=root_value
166+
)
157167
assert isinstance(awaitable_result, Awaitable)
158168
result = await awaitable_result
159169

tests/execution/test_nonnull.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ async def promiseNonNullNest(self, _info):
9696

9797

9898
def execute_query(query, root_value):
99-
return execute(schema, parse(query), root_value)
99+
return execute(schema=schema, document=parse(query), root_value=root_value)
100100

101101

102+
# avoids also doing any nests
102103
def patch(data):
103104
return re.sub(
104105
r"\bsyncNonNull\b", "promiseNonNull", re.sub(r"\bsync\b", "promise", data)

0 commit comments

Comments
 (0)