Skip to content

MiddlewareContext in @nestjs/graphql assumes 'info' is always present on the context object #2824

@einkria

Description

@einkria

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

In @nestjs/graphql 11.0.4 there is an interface called MiddlewareContext. There the assumption is made that the field
info: GrapQLResolveInfo
is always present on the context object. That however is not true. Info can be null or undefined. In our case the info field is not present on qraphql sub-requests. We are using @apollo/client 3.7.10.

Further info:

  • For graphQL we use federation and generate the schema with the code-first approach
  • We observed the issue in a query that returns an entity which contains an external field (sub-request)
  • The external field is resolved to the correct sub-graph, but in the sub-graph's field middleware we receive a context that does not adhere to the MiddlewareContext interface
    • info is undefined

Minimum reproduction code

https://stackblitz.com/edit/nestjs-typescript-starter-vxhuhx?file=src%2Fmiddleware.ts

Steps to reproduce

See code snippet.

Expected behavior

Info field is made optional on the MiddlewareContext object to reflect the actuality of the GraphQL implementation.

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

@nestjs/graphql

NestJS version

9.3.12

Packages versions

[Nest Platform Information]
platform-express version : 9.3.12
event-emitter version : 1.4.1
schematics version : 9.0.4
throttler version : 4.0.0
schedule version : 2.2.0
terminus version : 9.2.2
graphql version : 11.0.4
swagger version : 6.2.1
typeorm version : 9.0.1
testing version : 9.3.12
apollo version : 11.0.4
common version : 9.3.12
config version : 2.3.1
axios version : 2.0.0
core version : 9.3.12

Node.js version

16.19.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions