You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using ariadne/gunicorn/uvicorn to create a GraphQL service in ASGI style. For authorization, we plan to do it on resolver layer and to achieve so, we use context_value to pass user info as part of request (which I also learn from this forum). The user info is provided via encoded jwt context as part of request body. So we first decode it and then append back to the request at server layer. The issue we encountered is that when we try to access the request value from context info in resolver, the request is no longer the one we expected, but overwritten by some other request.
To recap:
get request from ASGI HTTP scope
init GraphqlApp with context_value = {"request: request"}
class App:
graphqlApp
def get_context(request: Request):
return {"request": request}
async def __call__(scope, receive, send):
request= Request(scope)...
if not this.graphqlApp:
self.graphqlApp = new Graph (... context_value = get_context(request), ...) (run only once)
if request.method = 'post':
request = parse_jwt(request)
await self.graphqlApp(scope, receive, send)
....
....
whenever a http service request comes in, resolve the user info from encoded jwt and append back to request
access request via info.context in resolver
Why does the request we get in the resolver is not the one we are expecting? How can I make it work?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi there,
I am using ariadne/gunicorn/uvicorn to create a GraphQL service in ASGI style. For authorization, we plan to do it on resolver layer and to achieve so, we use context_value to pass user info as part of request (which I also learn from this forum). The user info is provided via encoded jwt context as part of request body. So we first decode it and then append back to the request at server layer. The issue we encountered is that when we try to access the request value from context info in resolver, the request is no longer the one we expected, but overwritten by some other request.
To recap:
class App:
graphqlApp
Why does the request we get in the resolver is not the one we are expecting? How can I make it work?
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions