Skip to content

How can I use fast api dependency injection in ariadne? #623

Answered by rafalp
MilanRgm asked this question in Q&A
Discussion options

You must be logged in to vote

@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.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@ppbpdx
Comment options

@rafalp
Comment options

@ppbpdx
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by rafalp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants