ApolloServerPluginLandingPageLocalDefault从@apollo/server与NestJS GraphQLModule配置不兼容。

huangapple go评论104阅读模式
英文:

ApolloServerPluginLandingPageLocalDefault from @apollo/server is not compatible with NestJS GraphQLModule config

问题

I am migrating my NestJS application from Apollo v3 to Apollo v4, but I encountered a problem. Following the migration guide here I modified the import statement for the local landing page:

  1. import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
  2. import { Module } from '@nestjs/common';
  3. import { GraphQLModule } from '@nestjs/graphql';
  4. import { join } from 'path';
  5. import { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default'; //was 'apollo-server-core'
  6. import { DenunciaDetallesModule } from './registry/denuncia-detalles/denuncia-detalles.module';
  7. @Module({
  8. imports: [
  9. GraphQLModule.forRoot<ApolloDriverConfig>({
  10. autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
  11. sortSchema: true,
  12. driver: ApolloDriver,
  13. playground: false,
  14. plugins: [ApolloServerPluginLandingPageLocalDefault()],
  15. }),
  16. DenunciaDetallesModule,
  17. ],
  18. })
  19. export class AppModule {}

However, when running the API, I get the following error:

  1. src/app.module.ts:15:17 - error TS2322: Type 'ApolloServerPlugin<BaseContext>' is not assignable to type 'PluginDefinition'.
  2. Types of property 'serverWillStart' are incompatible.
  3. Type '(service: GraphQLServerContext) => Promise<void | GraphQLServerListener>' is not assignable to type '(service: GraphQLServiceContext) => Promise<void | GraphQLServerListener>'.
  4. Types of parameters 'service' and 'service' are incompatible.
  5. Type 'GraphQLServiceContext' is missing the following properties from type 'GraphQLServerContext': cache, startedInBackground
  6. 15 plugins: [ApolloServerPluginLandingPageLocalDefault()],

I could just switch back to apollo-server-core, but I don't understand why the types are not compatible if I updated all packages and made a clean install. Here are my dependencies:

  1. "dependencies": {
  2. "@apollo/server": "^4.7.4",
  3. "@nestjs/apollo": "^10.1.7",
  4. "@nestjs/class-validator": "^0.13.4",
  5. "@nestjs/common": "^9.0.0",
  6. "@nestjs/core": "^9.0.0",
  7. "@nestjs/graphql": "^10.1.7",
  8. "@nestjs/platform-express": "^9.0.0",
  9. "@nestjs/swagger": "^6.1.3",
  10. "@types/mssql": "^8.1.1",
  11. "apollo-server-core": "^3.12.0",
  12. "apollo-server-express": "^3.12.0",
  13. "class-transformer": "^0.5.1",
  14. "class-validator": "^0.13.2",
  15. "graphql": "^16.6.0",
  16. "joi": "^17.7.0",
  17. "mssql": "^9.1.1",
  18. "reflect-metadata": "^0.1.13",
  19. "rimraf": "^3.0.2",
  20. "rxjs": "^7.2.0",
  21. "typeorm": "^0.3.11"
  22. }
英文:

I am migrating my NestJS application from Apollo v3 to Apollo v4, but I encountered a problem.
Following the migration guide here
I modified the import statement for the local landing page:

  1. import { ApolloDriver, ApolloDriverConfig } from &#39;@nestjs/apollo&#39;;
  2. import { Module } from &#39;@nestjs/common&#39;;
  3. import { GraphQLModule } from &#39;@nestjs/graphql&#39;;
  4. import { join } from &#39;path&#39;;
  5. import { ApolloServerPluginLandingPageLocalDefault } from &#39;@apollo/server/plugin/landingPage/default&#39;; //was &#39;apollo-server-core&#39;
  6. import { DenunciaDetallesModule } from &#39;./registry/denuncia-detalles/denuncia-detalles.module&#39;;
  7. @Module({
  8. imports: [
  9. GraphQLModule.forRoot&lt;ApolloDriverConfig&gt;({
  10. autoSchemaFile: join(process.cwd(), &#39;src/schema.gql&#39;),
  11. sortSchema: true,
  12. driver: ApolloDriver,
  13. playground: false,
  14. plugins: [ApolloServerPluginLandingPageLocalDefault()],
  15. }),
  16. DenunciaDetallesModule,
  17. ],
  18. })
  19. export class AppModule {}

However, when running the API, I get the following error:

  1. src/app.module.ts:15:17 - error TS2322: Type &#39;ApolloServerPlugin&lt;BaseContext&gt;&#39; is not assignable to type &#39;PluginDefinition&#39;.
  2. Types of property &#39;serverWillStart&#39; are incompatible.
  3. Type &#39;(service: GraphQLServerContext) =&gt; Promise&lt;void | GraphQLServerListener&gt;&#39; is not assignable to type &#39;(service: GraphQLServiceContext) =&gt; Promise&lt;void | GraphQLServerListener&gt;&#39;.
  4. Types of parameters &#39;service&#39; and &#39;service&#39; are incompatible.
  5. Type &#39;GraphQLServiceContext&#39; is missing the following properties from type &#39;GraphQLServerContext&#39;: cache, startedInBackground
  6. 15 plugins: [ApolloServerPluginLandingPageLocalDefault()],

I could just switch back to apollo-server-core, but I don't understand why the types are not compatible if I updated all packages and made a clean install. Here are my dependencies:

  1. &quot;dependencies&quot;: {
  2. &quot;@apollo/server&quot;: &quot;^4.7.4&quot;,
  3. &quot;@nestjs/apollo&quot;: &quot;^10.1.7&quot;,
  4. &quot;@nestjs/class-validator&quot;: &quot;^0.13.4&quot;,
  5. &quot;@nestjs/common&quot;: &quot;^9.0.0&quot;,
  6. &quot;@nestjs/core&quot;: &quot;^9.0.0&quot;,
  7. &quot;@nestjs/graphql&quot;: &quot;^10.1.7&quot;,
  8. &quot;@nestjs/platform-express&quot;: &quot;^9.0.0&quot;,
  9. &quot;@nestjs/swagger&quot;: &quot;^6.1.3&quot;,
  10. &quot;@types/mssql&quot;: &quot;^8.1.1&quot;,
  11. &quot;apollo-server-core&quot;: &quot;^3.12.0&quot;,
  12. &quot;apollo-server-express&quot;: &quot;^3.12.0&quot;,
  13. &quot;class-transformer&quot;: &quot;^0.5.1&quot;,
  14. &quot;class-validator&quot;: &quot;^0.13.2&quot;,
  15. &quot;graphql&quot;: &quot;^16.6.0&quot;,
  16. &quot;joi&quot;: &quot;^17.7.0&quot;,
  17. &quot;mssql&quot;: &quot;^9.1.1&quot;,
  18. &quot;reflect-metadata&quot;: &quot;^0.1.13&quot;,
  19. &quot;rimraf&quot;: &quot;^3.0.2&quot;,
  20. &quot;rxjs&quot;: &quot;^7.2.0&quot;,
  21. &quot;typeorm&quot;: &quot;^0.3.11&quot;
  22. },

答案1

得分: 1

@nestjs/apollo@^10 兼容于 apollo 3。要使用 apollo 4,您需要使用 @nestjs/apollo@^11

英文:

@nestjs/apollo@^10 is comptible with apollo 3. To use apollo 4 you need to use @nestjs/apollo@^11

huangapple
  • 本文由 发表于 2023年6月29日 23:22:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76582465.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定