New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Impossible to fetch the context from the graphQLOptions in the resolver #38
Comments
So after multiple attempts in debug mode, etc... the this weird parameter values are due to the use of the async keyword (tested in v5.1.0/v5.0.0/v4.61). Without it, it works as expected. This needs a fix. Let me know if I can help :) |
Any update on this by any chance? |
@hloos I don't get your issue. If you like to add something to the context you simply can add information like so graphqlExpress(async req => ({
schema,
rootValue: req,
context: { foo: 'bar' },
})) If you following the documentation related to graphqlExpress(async req => ({
schema,
rootValue: req,
context: req,
})) You will find yourself an user object in your resolvers. @Query('currentUser')
async currentUser(obj, args, context: Context): Promise<User> {
const currentUser = context.user;
return await this.userService.findById(currentUser.id);
} |
@YemSalat the workaround I am using consists in removing the async keyword from the main method (the one annotated with @query) and using another class method (with async keyword) to do the await I need. @cschroeter your example is quite similar to mine (only the signature method seems different). I am not sure how it can work... |
It should be easy to achieve in the latest module release (which support Apollo v2). Let me know if you face any issue once upgraded. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Playing with the graphql sample provided in the samples of nestjs, I was looking for a way to fetch the context in the resolver in order to extract user token in the header of the request to forward it to other backend services.
Unfortunately, it does not seem to be given as parameter despite its presence in the method signature -> findByOneId.
Here follows the context added to each request and expected in the resolver method call (object ->req.headers)...
All parameters are undefined except the args one which contains the id.
Moreover, I figured out other unexpected behaviors when adding decorators to the method:
Here all arguments are undefined except the args one which contains... the context !! (same issue when replacing the
@Req()
with@Body()
)2 decorators allows here to fetch the whole
GraphQLOptions
in the args parameter (other param still undefined). Same behavior for the signatureasync findOneById(args): Promise<Cat>
.The text was updated successfully, but these errors were encountered: