Skip to content

Commit

Permalink
fix(graphql): add info on how to migrate, import only from root files
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jan 24, 2022
1 parent 069f362 commit bc68510
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/apollo/lib/drivers/apollo-base.driver.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 1 addition & 2 deletions packages/apollo/lib/drivers/apollo-federation.driver.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
7 changes: 5 additions & 2 deletions packages/apollo/lib/drivers/apollo.driver.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
3 changes: 1 addition & 2 deletions packages/apollo/lib/services/plugins-explorer.service.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
20 changes: 17 additions & 3 deletions packages/graphql/lib/graphql.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Inject, Module } from '@nestjs/common';
import { Inject, Logger, Module } from '@nestjs/common';
import {
DynamicModule,
OnModuleDestroy,
Expand Down Expand Up @@ -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;
}
Expand All @@ -59,9 +61,15 @@ export class GraphQLModule<
private readonly graphQlTypesLoader: GraphQLTypesLoader,
) {}

async onModuleDestroy() {
await this._graphQlAdapter.stop();
}

static forRoot<TOptions extends Record<string, any> = GqlModuleOptions>(
options: TOptions = {} as TOptions,
): DynamicModule {
this.assertDriver(options);

return {
module: GraphQLModule,
providers: [
Expand All @@ -80,6 +88,7 @@ export class GraphQLModule<
static forRootAsync<TOptions extends Record<string, any> = GqlModuleOptions>(
options: GqlModuleAsyncOptions<TOptions, GqlOptionsFactory<TOptions>>,
): DynamicModule {
this.assertDriver(options);
return {
module: GraphQLModule,
imports: options.imports,
Expand Down Expand Up @@ -150,7 +159,12 @@ export class GraphQLModule<
});
}

async onModuleDestroy() {
await this._graphQlAdapter.stop();
private static assertDriver(options: Record<string, any>) {
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);
}
}
}
2 changes: 2 additions & 0 deletions packages/graphql/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit bc68510

Please sign in to comment.