If I pass context function to createGraphQLHandler, it is only called once on first request and then context is same for all subsequent requests. (when running yarn rw dev). I was expecting userContext to run on every request.
Hello @peterp - Can you please point me in right direction If above code is non how userContext should be used? Otherwise if it’s bug I can file bug report. Thanks!
In fact I considered that before and choose userContext function because it receives event and since event is request specific I thought it will be called everytime.
Ah ok, I see you’re trying to implement a custom solution! And I think there’s a shortcoming in my design!
I would love to make a second argument include the event - but in the meantime I’ll debug your current solution to figure out why it’s only firing once.
I have tried to debug in a limited way and found two things if that helps you,
if I pass getCurrentUser and context both to createGraphQLHandler. getCurrentUser is called on every request but context is called only on first request.
If I don’t use createGraphQLHandler and create ApolloServer handler myself then context I passed will be called on every request.
And again this is when running dev-server. I don’t know how this behaves on AWS Lambda or Netlify functions
I found possible issue, userContext was overwritten after first run and this patch may be fix it. Although after patch I ran tests and all passed but before I submit pull request can you please check. You can check diff on following link,
@peterp with this bug same user will be logged in for all subsequent requests regardless of from where that request came in. I don’t know if anyone else is using context as a function but since it’s standard ApolloServer config it should be working with RedwoodJS