RN extensions can be singleton instances meaning that the execution context can change during
lifepsan hook execution (if you have parallel operaitons running) :
async def test_execution_context_distinct_on_parallel_execution():
class EnsureDistinctExtension(SchemaExtension):
def __init__(self) -> None:
...
async def on_operation(self) -> AsyncIterator[None]:
query = self.execution_context.query
yield
assert self.execution_context.query == query
@strawberry.type
class Query:
@strawberry.field
async def foo(self) -> str:
await asyncio.sleep(0.01)
return "pong"
@strawberry.field
async def bar(self) -> str:
await asyncio.sleep(0.02)
return "pong"
schema = strawberry.Schema(query=Query, extensions=[EnsureDistinctExtension()])
query_foo = "query foo { foo }"
query_bar = "query bar { bar }"
for _ in range(10):
results = await asyncio.gather(*[schema.execute(query_foo), schema.execute(query_bar)])
for res in results:
assert not res.errors
I want to remove the execution_context from the extension instance and provide it as an argument to each hook
what do you guys think?
original discussion on discord
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too