From bc68510603af7dd6f938008bcd1f93b3ab45d2e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20My=C5=9Bliwiec?= Date: Mon, 24 Jan 2022 15:38:51 +0100 Subject: [PATCH] fix(graphql): add info on how to migrate, import only from root files --- .../apollo/lib/drivers/apollo-base.driver.ts | 2 +- .../lib/drivers/apollo-federation.driver.ts | 3 +-- packages/apollo/lib/drivers/apollo.driver.ts | 7 +++++-- .../lib/services/plugins-explorer.service.ts | 3 +-- packages/graphql/lib/graphql.module.ts | 20 ++++++++++++++++--- packages/graphql/lib/index.ts | 2 ++ 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/packages/apollo/lib/drivers/apollo-base.driver.ts b/packages/apollo/lib/drivers/apollo-base.driver.ts index 82f0f9f53..7d60dc4bc 100644 --- a/packages/apollo/lib/drivers/apollo-base.driver.ts +++ b/packages/apollo/lib/drivers/apollo-base.driver.ts @@ -1,7 +1,7 @@ import { HttpStatus } from '@nestjs/common'; import { loadPackage } from '@nestjs/common/utils/load-package.util'; import { isFunction } from '@nestjs/common/utils/shared.utils'; -import { AbstractGraphQLDriver } from '@nestjs/graphql/drivers/abstract-graphql.driver'; +import { AbstractGraphQLDriver } from '@nestjs/graphql'; import { ApolloError, ApolloServerBase, diff --git a/packages/apollo/lib/drivers/apollo-federation.driver.ts b/packages/apollo/lib/drivers/apollo-federation.driver.ts index b8d8bc0eb..6f39318c9 100644 --- a/packages/apollo/lib/drivers/apollo-federation.driver.ts +++ b/packages/apollo/lib/drivers/apollo-federation.driver.ts @@ -1,8 +1,7 @@ import { Injectable } from '@nestjs/common'; import { loadPackage } from '@nestjs/common/utils/load-package.util'; import { ModulesContainer } from '@nestjs/core'; -import { GraphQLFederationFactory } from '@nestjs/graphql/federation/graphql-federation.factory'; -import { extend } from '@nestjs/graphql/utils/extend.util'; +import { extend, GraphQLFederationFactory } from '@nestjs/graphql'; import { ApolloDriverConfig } from '../interfaces'; import { PluginsExplorerService } from '../services/plugins-explorer.service'; import { ApolloBaseDriver } from './apollo-base.driver'; diff --git a/packages/apollo/lib/drivers/apollo.driver.ts b/packages/apollo/lib/drivers/apollo.driver.ts index 7d041024e..3aee010c5 100644 --- a/packages/apollo/lib/drivers/apollo.driver.ts +++ b/packages/apollo/lib/drivers/apollo.driver.ts @@ -1,7 +1,10 @@ import { Injectable } from '@nestjs/common'; import { ModulesContainer } from '@nestjs/core'; -import { GqlSubscriptionService, SubscriptionConfig } from '@nestjs/graphql'; -import { extend } from '@nestjs/graphql/utils'; +import { + extend, + GqlSubscriptionService, + SubscriptionConfig, +} from '@nestjs/graphql'; import { printSchema } from 'graphql'; import { ApolloDriverConfig } from '../interfaces'; import { PluginsExplorerService } from '../services/plugins-explorer.service'; diff --git a/packages/apollo/lib/services/plugins-explorer.service.ts b/packages/apollo/lib/services/plugins-explorer.service.ts index 2c9e25150..4ed3d9fac 100644 --- a/packages/apollo/lib/services/plugins-explorer.service.ts +++ b/packages/apollo/lib/services/plugins-explorer.service.ts @@ -1,7 +1,6 @@ import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper'; import { ModulesContainer } from '@nestjs/core/injector/modules-container'; -import { GqlModuleOptions } from '@nestjs/graphql/interfaces/gql-module-options.interface'; -import { BaseExplorerService } from '@nestjs/graphql/services/base-explorer.service'; +import { BaseExplorerService, GqlModuleOptions } from '@nestjs/graphql'; import { PLUGIN_METADATA } from '../apollo.constants'; export class PluginsExplorerService extends BaseExplorerService { diff --git a/packages/graphql/lib/graphql.module.ts b/packages/graphql/lib/graphql.module.ts index 7eae3223f..add66a3b6 100644 --- a/packages/graphql/lib/graphql.module.ts +++ b/packages/graphql/lib/graphql.module.ts @@ -1,4 +1,4 @@ -import { Inject, Module } from '@nestjs/common'; +import { Inject, Logger, Module } from '@nestjs/common'; import { DynamicModule, OnModuleDestroy, @@ -48,6 +48,8 @@ export class GraphQLModule< TAdapter extends AbstractGraphQLDriver = AbstractGraphQLDriver, > implements OnModuleInit, OnModuleDestroy { + private static readonly logger = new Logger('GraphQLModule'); + get graphQlAdapter(): TAdapter { return this._graphQlAdapter as TAdapter; } @@ -59,9 +61,15 @@ export class GraphQLModule< private readonly graphQlTypesLoader: GraphQLTypesLoader, ) {} + async onModuleDestroy() { + await this._graphQlAdapter.stop(); + } + static forRoot = GqlModuleOptions>( options: TOptions = {} as TOptions, ): DynamicModule { + this.assertDriver(options); + return { module: GraphQLModule, providers: [ @@ -80,6 +88,7 @@ export class GraphQLModule< static forRootAsync = GqlModuleOptions>( options: GqlModuleAsyncOptions>, ): DynamicModule { + this.assertDriver(options); return { module: GraphQLModule, imports: options.imports, @@ -150,7 +159,12 @@ export class GraphQLModule< }); } - async onModuleDestroy() { - await this._graphQlAdapter.stop(); + private static assertDriver(options: Record) { + if (!options.driver) { + const errorMessage = + 'Missing "driver" option. In the latest version of "@nestjs/graphql" package (v10) a new required configuration property called "driver" has been introduced. Check out the official documentation for more details on how to migrate ("Quick start" chapter).'; + this.logger.error(errorMessage); + throw new Error(errorMessage); + } } } diff --git a/packages/graphql/lib/index.ts b/packages/graphql/lib/index.ts index 04ccb2646..8b1fc5fd0 100644 --- a/packages/graphql/lib/index.ts +++ b/packages/graphql/lib/index.ts @@ -10,9 +10,11 @@ export * from './graphql.module'; export * from './interfaces'; export * from './scalars'; export * from './schema-builder'; +export * from './services/base-explorer.service'; export * from './services/gql-arguments-host'; export * from './services/gql-execution-context'; export * from './services/gql-subscription.service'; export * from './tokens'; export * from './type-factories'; export * from './type-helpers'; +export * from './utils/extend.util';