Context and DataSources in @apollo/server v4 #562
Replies: 1 comment 1 reply
-
Ok so I sort of understand what my issue is now. For some reason, the But I was able to fix my issue by creating a middleware that is executed before all my other middlewares. And I did something like this:
In this snippet, my middleware grabs the context one of my datasources receives (which is a class instance) and passed that down. In this way, in my other middlewares if I actually modify the context, it will reflect the changes also in my datasources context instance. I don't like this but it works until there is a better solution. Any ideas on why the context isn't a reference to the same one passed to my datasources? |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am using this library in my project in order to handle particular cases.
In a specific case, I created an authentication middleware to handle the validation of the token provided by a user to make sure its valid and if it is, query my datasource to fetch the user.
This works fine, I am able to do so and pass the user object to my context so it goes to my resolvers.
My issue, is that since the way DataSources works in the v4 of @apollo/server, the context object that I pass down to my DataSources do not contain any changes or additions that I would add via middlewares.
I was hoping anyone had any idea on how I could approach this issue?
Beta Was this translation helpful? Give feedback.
All reactions