-
If used starlette graphqlapp then we can do the following from starlette.graphql import GraphQLApp
graphql_app = GraphQLApp(schema=graphene.Schema(query=Query))
@app.get('/')
async def graphiql(request: Request):
request._url = URL('/gql')
return await graphql_app.handle_graphiql(request=request)
@app.post('/gql')
async def graphql(request: Request, db: Session = Depends(get_db)):
request.state.db = db
return await graphql_app.handle_graphql(request=request) but I have no idea while using ariadne. Initially, I tried to use dependency injection as following async def resolve_graphql_context(
request: Request, db: Session = Depends(get_db)
) -> GraphQLContext:
return await get_graphql_context(request, db)
graphql = GraphQL(schema, debug=True, context_value=resolve_graphql_context) But I came to know that it works only on fastapi route. How can I now use it on ariadne? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I think you want to use I hope this helps you. |
Beta Was this translation helpful? Give feedback.
-
@Tushant response updated for Ariadne 0.16 and later: # Unpack HTTP handler from `GraphQL` app:
graphql_app = GraphQL(schema).http_handler
@app.get('/')
async def graphiql(request: Request):
request._url = URL('/gql')
return await graphql_app.render_playground(request)
@app.post('/gql')
async def graphql(request: Request, db: Session = Depends(get_db)):
request.state.db = db
return await graphql_app.graphql_http_server(request) I agree we could do better here. So here's #998 to track this. |
Beta Was this translation helpful? Give feedback.
@Tushant response updated for Ariadne 0.16 and later:
I agree we could do better here. So here's #998 to track this.