Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add session argument for GraphQLApp() constructor #1297

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions starlette/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ def __init__(
schema: "graphene.Schema",
executor_class: type = None,
graphiql: bool = True,
session: "sqlalchemy.orm.Session" = None,
) -> None:
self.schema = schema
self.graphiql = graphiql
self.executor_class = executor_class
self.is_async = executor_class is not None and issubclass(
executor_class, AsyncioExecutor
)
self.session = session

async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
if self.executor_class is not None:
Expand Down Expand Up @@ -94,6 +96,8 @@ async def handle_graphql(self, request: Request) -> Response:

background = BackgroundTasks()
context = {"request": request, "background": background}
if self.session:
context['session'] = self.session

result = await self.execute(
query, variables=variables, context=context, operation_name=operation_name
Expand Down