Skip to content
Advertisement

Strawberry+FastAPI: How to get request-info in a dependency?

Consider this code:

JavaScript

How do I get the request info in the dependencies custom_context_dependency and has_root_access?

Advertisement

Answer

When I tried FastAPI’s Request, it was still showing some error when Strawberry’s page was opened. Later I understood that the error was being raised by WebSocket connection. So my solution was to make request and web-socket optional params:

JavaScript

Either request or websocket will be present for every request.

To get a header specifically, FastAPI’s Header is also supported.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement