Skip to content

Commit

Permalink
Merge pull request #170 from evo-company/add-result-to-ExecutionResult
Browse files Browse the repository at this point in the history
add result field to ExecutionResult
  • Loading branch information
kindermax authored Sep 19, 2024
2 parents 3a7a0ba + 778d267 commit 0ea5d9e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
14 changes: 8 additions & 6 deletions hiku/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Generic,
)

from hiku.result import Proxy
from hiku.cache import CacheSettings
from hiku.context import (
ExecutionContext,
Expand Down Expand Up @@ -58,6 +59,7 @@ def _run_validation(
class ExecutionResult:
data: Optional[Dict[str, Any]]
errors: Optional[List[GraphQLError]]
result: Optional[Proxy]


class Schema(Generic[_ExecutorType]):
Expand Down Expand Up @@ -158,13 +160,13 @@ def execute_sync(
execution_context.operation_type_name,
).process(execution_context.query)

return ExecutionResult(data, None)
return ExecutionResult(data, None, result)
except ValidationError as e:
return ExecutionResult(
None, [GraphQLError(message) for message in e.errors]
None, [GraphQLError(message) for message in e.errors], None
)
except GraphQLError as e:
return ExecutionResult(None, [e])
return ExecutionResult(None, [e], None)

async def execute(
self: "Schema[BaseAsyncExecutor]",
Expand Down Expand Up @@ -213,13 +215,13 @@ async def execute(
execution_context.operation_type_name,
).process(execution_context.query)

return ExecutionResult(data, None)
return ExecutionResult(data, None, result)
except ValidationError as e:
return ExecutionResult(
None, [GraphQLError(message) for message in e.errors]
None, [GraphQLError(message) for message in e.errors], None
)
except GraphQLError as e:
return ExecutionResult(None, [e])
return ExecutionResult(None, [e], None)

def _validate(
self,
Expand Down
12 changes: 3 additions & 9 deletions tests/test_endpoint_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@ async def answer(ctx, fields):


def test_endpoint(sync_graph):
endpoint = GraphQLEndpoint(
Schema(SyncExecutor(), sync_graph)
)
endpoint = GraphQLEndpoint(Schema(SyncExecutor(), sync_graph))
result = endpoint.dispatch({"query": "{answer}"})
assert result == {"data": {"answer": "42"}}


def test_batch_endpoint(sync_graph):
endpoint = BatchGraphQLEndpoint(
Schema(SyncExecutor(), sync_graph)
)
endpoint = BatchGraphQLEndpoint(Schema(SyncExecutor(), sync_graph))

assert endpoint.dispatch([]) == []

Expand All @@ -63,9 +59,7 @@ def test_batch_endpoint(sync_graph):

@pytest.mark.asyncio
async def test_async_endpoint(async_graph):
endpoint = AsyncGraphQLEndpoint(
Schema(AsyncIOExecutor(), async_graph)
)
endpoint = AsyncGraphQLEndpoint(Schema(AsyncIOExecutor(), async_graph))
result = await endpoint.dispatch(
{"query": "{answer}"}, context={"default_answer": "52"}
)
Expand Down

0 comments on commit 0ea5d9e

Please sign in to comment.