|
1 | 1 | import asyncio
|
2 |
| -from typing import cast, Any, Awaitable, Optional |
3 |
| - |
4 |
| -from pytest import mark, raises |
| 2 | +from typing import Any, Awaitable, Optional, cast |
5 | 3 |
|
6 | 4 | from graphql.error import GraphQLError
|
7 | 5 | from graphql.execution import execute, execute_sync
|
8 |
| -from graphql.language import parse, FieldNode, OperationDefinitionNode |
9 |
| -from graphql.pyutils import inspect, Undefined |
| 6 | +from graphql.language import FieldNode, OperationDefinitionNode, parse |
| 7 | +from graphql.pyutils import Undefined, inspect |
10 | 8 | from graphql.type import (
|
11 | 9 | GraphQLArgument,
|
12 | 10 | GraphQLBoolean,
|
|
17 | 15 | GraphQLNonNull,
|
18 | 16 | GraphQLObjectType,
|
19 | 17 | GraphQLResolveInfo,
|
20 |
| - GraphQLSchema, |
21 | 18 | GraphQLScalarType,
|
| 19 | + GraphQLSchema, |
22 | 20 | GraphQLString,
|
23 | 21 | GraphQLUnionType,
|
24 | 22 | ResponsePath,
|
25 | 23 | )
|
| 24 | +from pytest import mark, raises |
26 | 25 |
|
27 | 26 |
|
28 | 27 | def describe_execute_handles_basic_execution_tasks():
|
@@ -567,6 +566,56 @@ async def asyncReturnErrorWithExtensions(self, _info):
|
567 | 566 | ],
|
568 | 567 | )
|
569 | 568 |
|
| 569 | + def handles_sync_errors_combined_with_async_ones(): |
| 570 | + is_async_resolver_finished = False |
| 571 | + |
| 572 | + async def async_resolver(_obj, _info): |
| 573 | + nonlocal is_async_resolver_finished |
| 574 | + sleep = asyncio.sleep |
| 575 | + sleep(0) |
| 576 | + sleep(0) |
| 577 | + sleep(0) |
| 578 | + is_async_resolver_finished = True |
| 579 | + |
| 580 | + schema = GraphQLSchema( |
| 581 | + GraphQLObjectType( |
| 582 | + "Query", |
| 583 | + { |
| 584 | + "syncNullError": GraphQLField( |
| 585 | + GraphQLNonNull(GraphQLString), resolve=lambda _obj, _info: None |
| 586 | + ), |
| 587 | + "asyncNullError": GraphQLField( |
| 588 | + GraphQLNonNull(GraphQLString), resolve=async_resolver |
| 589 | + ), |
| 590 | + }, |
| 591 | + ) |
| 592 | + ) |
| 593 | + |
| 594 | + document = parse( |
| 595 | + """ |
| 596 | + { |
| 597 | + asyncNullError |
| 598 | + syncNullError |
| 599 | + } |
| 600 | + """ |
| 601 | + ) |
| 602 | + |
| 603 | + result = execute(schema, document) |
| 604 | + |
| 605 | + assert is_async_resolver_finished is False |
| 606 | + |
| 607 | + assert result == ( |
| 608 | + None, |
| 609 | + [ |
| 610 | + { |
| 611 | + "message": "Cannot return null" |
| 612 | + " for non-nullable field Query.syncNullError.", |
| 613 | + "locations": [(4, 15)], |
| 614 | + "path": ["syncNullError"], |
| 615 | + } |
| 616 | + ], |
| 617 | + ) |
| 618 | + |
570 | 619 | def full_response_path_is_included_for_non_nullable_fields():
|
571 | 620 | def resolve_ok(*_args):
|
572 | 621 | return {}
|
|
0 commit comments