Graphql: Missing modules after update

Created on 9 Jul 2021  路  7Comments  路  Source: nestjs/graphql

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When I update NestJS to the newest version, the @nestjs/graphql can't find some modules during build.
image

Expected behavior

The project should build.

Minimal reproduction of the problem with instructions

  1. Create new NestJS project
  2. Update packages to the newest version
  3. Install GraphQL packages @nestjs/graphql graphql-tools graphql apollo-server-express
  4. Import the GraphQL module
  5. run yarn build

Environment


Nest version: 8.0.0


For Tooling issues:
- Node version: v14.17.0
- Platform:  Linux and Windows 

Most helpful comment

That's actually something that we've been struggling with for a while already.

Both packages (ts-morph and @apollo/gateway) are _optional_. For example, if you're building a code-first GraphQL application (not federated), neither library is technically required. A different example would be if you had a code-first GQL Federated API, in this case, you need the @apollo/gateway library, but you'd never really interact with the ts-morph.

In the past, both libraries were included (auto-installed) by default as they were specified as "optionalDependencies". Now, they are registered as optional "peerDependencies" so their behavior will differ depending on what NPM version (NPM v7 automatically installs peer deps) you use/tsconfig settings you have. We made that change (moved these packages to the peerDependencies section) because ts-morph is quite a heavy package (since it's a compiler wrapper), not needed for all code first GraphQL apps.

Solutions:
a) manually install both deps (npm i ts-morph @apollo/gateway)
b) OR disable lib types checking in your tsconfig.json file (compilerOptions.skipLibCheck set to true) - this is the default value for new Nest projects as well

All 7 comments

The missing modules are ts-morph and @apollo/gateway. That was in the screenshot. I'm adding this comment to make it searchable.

I worked around this by adding the modules as dependencies in my project. I'd prefer not to have these "sub-dependencies" referenced in package.json.

That's actually something that we've been struggling with for a while already.

Both packages (ts-morph and @apollo/gateway) are _optional_. For example, if you're building a code-first GraphQL application (not federated), neither library is technically required. A different example would be if you had a code-first GQL Federated API, in this case, you need the @apollo/gateway library, but you'd never really interact with the ts-morph.

In the past, both libraries were included (auto-installed) by default as they were specified as "optionalDependencies". Now, they are registered as optional "peerDependencies" so their behavior will differ depending on what NPM version (NPM v7 automatically installs peer deps) you use/tsconfig settings you have. We made that change (moved these packages to the peerDependencies section) because ts-morph is quite a heavy package (since it's a compiler wrapper), not needed for all code first GraphQL apps.

Solutions:
a) manually install both deps (npm i ts-morph @apollo/gateway)
b) OR disable lib types checking in your tsconfig.json file (compilerOptions.skipLibCheck set to true) - this is the default value for new Nest projects as well

For those (like me) getting errors like

UnhandledPromiseRejectionWarning: Error: You must `await server.start()` before calling `server.apply Middleware()`

when using "apollo-server-express": "^3.0.0", there's already a fix https://github.com/nestjs/graphql/pull/1627 on the way 馃檶

Thank you. I was able to get things working by setting compilerOptions.skipLibCheck to true (not false, I believe that was a typo).

My tsconfig.json was created under Nest 7.x and didn't have skipLibCheck set so that was why I was seeing the error.

My solution is neither a) nor b), I prefer to c) explicitly declare the few missing types over skipping library type checks alltogether, on the other hand I did not run in any import issues with ts-morph so far.

// src/graphql-gateway-type-shim.d.ts

declare module '@apollo/gateway' {
    export interface GatewayConfig { }
    export interface ServiceEndpointDefinition { }
}

declare module '@apollo/gateway/dist/datasources/types' {
    export interface GraphQLDataSource { }
}

Was this page helpful?
0 / 5 - 0 ratings