-
Notifications
You must be signed in to change notification settings - Fork 399
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
@nestjs/graphql 7.9.8 breaks retrieving the request from the context #1364
Comments
Seems similar to this issue: #48 |
Please provide a minimum reproduction repository. |
I'm trying pretty hard to replicate the issue using the schema-first sample repo. This is how it presents in my e2e tests
at this point the req is in the context at this point it's gone from the context |
I've been trying to build a minimum repro but it's taking a lot of time.
It's clear to me now that the error where the request is missing from the context is only happening on field resolvers. |
Ok so I worked out roughly what is going on.
So I'm still not sure why my guard is being executed on field resolvers. |
I also ran into what seems to be the same issue after upgrading from v7.6.0 to v7.9.11. Further testing showed that the regression is not present in v7.9.7. In my case, I have a global guard defined thus: providers: [
{
provide: APP_GUARD,
useClass: AuthGuard,
},
] Then I have a query like this: union CustomMappings = CustomProductMappings | CustomProductVariantMappings
type SearchResult {
# a bunch of simple fields omitted
customMappings: CustomMappings!
}
type Query {
search: [SearchResult!]!
} What I observe is that the Furthermore, when it is called the 2nd time for the for the top-level (working)
then for the second (erroring) call it is
I suspect the cause may be related to the fact that I have the following FieldResolver defined: @Resolver('CustomMappings')
export class CustomMappingsResolver {
constructor(@Inject(ELASTIC_SEARCH_OPTIONS) private options: DeepRequired<ElasticsearchOptions>) {}
@ResolveField()
__resolveType(value: any): string {
const productPropertyNames = Object.keys(this.options.customProductMappings);
return Object.keys(value).every(k => productPropertyNames.includes(k))
? 'CustomProductMappings'
: 'CustomProductVariantMappings';
}
} and is possibly related to #1340. Note I am not using |
The latest version has a regression which affects the Elasticsearch plugin's customMappings field resolver. See nestjs/graphql#1364
I'm submitting a...
Current behavior
I have a few Guards and Interceptors that access the Express request.
I added it to the GraphQL context like so:
based on a doc I read which for the life of me I can no longer find.
Anyways, I've isolated an issue down to one specific version upgrade from @nestjs/graphql 7.9.7 to @nestjs/graphql 7.9.8.
When I make that upgrade the request is no longer available in the context and my guards break.
Expected behavior
The req was available in the context in @nestjs/graphql 7.9.7.
I've looked through a diff of that version change and can't see anything that could break this.
I'm stumped.
Minimal reproduction of the problem with instructions
Add req to GraphQL context.
Try to retrieve it with @nestjs/graphql 7.9.8
What is the motivation / use case for changing the behavior?
Guards that need access to the request context
Environment
For Tooling issues:
Others:
NestJS + GraphQL + Express
The text was updated successfully, but these errors were encountered: