From 458cfbadeb88a025b309bf90f6e8b897c7eba53d Mon Sep 17 00:00:00 2001 From: Keadex <12099977+keadex@users.noreply.github.com> Date: Thu, 7 Oct 2021 16:54:49 +0200 Subject: [PATCH] fix(@nestjs/graphql) fix federated schema generated with code first approach Federated schema generated with the code first approach does not contain the directives. Closes #1597 --- lib/graphql-definitions.factory.ts | 2 +- lib/graphql-schema.builder.ts | 2 +- lib/graphql.factory.ts | 2 +- lib/graphql.module.ts | 2 +- tests/e2e/code-first-schema.spec.ts | 2 +- tests/e2e/graphql-sort-auto-schema.spec.ts | 3 ++- tests/e2e/graphql-sort-schema.spec.ts | 3 ++- 7 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/graphql-definitions.factory.ts b/lib/graphql-definitions.factory.ts index 668642e7a..29df5cdfc 100644 --- a/lib/graphql-definitions.factory.ts +++ b/lib/graphql-definitions.factory.ts @@ -3,7 +3,7 @@ import { loadPackage } from '@nestjs/common/utils/load-package.util'; import { isEmpty } from '@nestjs/common/utils/shared.utils'; import { gql } from 'apollo-server-core'; import * as chokidar from 'chokidar'; -import { printSchema } from 'graphql'; +import { printSchema } from '@apollo/federation'; import { DefinitionsGeneratorOptions, GraphQLAstExplorer, diff --git a/lib/graphql-schema.builder.ts b/lib/graphql-schema.builder.ts index 4ad6a0102..122add6e6 100644 --- a/lib/graphql-schema.builder.ts +++ b/lib/graphql-schema.builder.ts @@ -4,9 +4,9 @@ import { isString } from '@nestjs/common/utils/shared.utils'; import { GraphQLSchema, lexicographicSortSchema, - printSchema, specifiedDirectives, } from 'graphql'; +import { printSchema } from '@apollo/federation'; import { resolve } from 'path'; import { GRAPHQL_SDL_FILE_HEADER } from './graphql.constants'; import { GqlModuleOptions } from './interfaces'; diff --git a/lib/graphql.factory.ts b/lib/graphql.factory.ts index b77b3ce8a..f35c7e9e7 100644 --- a/lib/graphql.factory.ts +++ b/lib/graphql.factory.ts @@ -10,8 +10,8 @@ import { GraphQLSchema, GraphQLSchemaConfig, lexicographicSortSchema, - printSchema, } from 'graphql'; +import { printSchema } from '@apollo/federation'; import { forEach, isEmpty } from 'lodash'; import { DefinitionsGeneratorOptions, diff --git a/lib/graphql.module.ts b/lib/graphql.module.ts index 2c05df592..23722d0c7 100644 --- a/lib/graphql.module.ts +++ b/lib/graphql.module.ts @@ -9,7 +9,7 @@ import { loadPackage } from '@nestjs/common/utils/load-package.util'; import { ApplicationConfig, HttpAdapterHost } from '@nestjs/core'; import { MetadataScanner } from '@nestjs/core/metadata-scanner'; import { ApolloServerBase } from 'apollo-server-core'; -import { printSchema } from 'graphql'; +import { printSchema } from '@apollo/federation'; import { GraphQLAstExplorer } from './graphql-ast.explorer'; import { GraphQLSchemaBuilder } from './graphql-schema.builder'; import { GraphQLSchemaHost } from './graphql-schema.host'; diff --git a/tests/e2e/code-first-schema.spec.ts b/tests/e2e/code-first-schema.spec.ts index 0a75aff23..3285080d3 100644 --- a/tests/e2e/code-first-schema.spec.ts +++ b/tests/e2e/code-first-schema.spec.ts @@ -5,9 +5,9 @@ import { GraphQLSchema, IntrospectionField, IntrospectionSchema, - printSchema, TypeKind } from 'graphql'; +import { printSchema } from '@apollo/federation'; import { GRAPHQL_SDL_FILE_HEADER } from '../../lib/graphql.constants'; import { GraphQLSchemaBuilderModule, diff --git a/tests/e2e/graphql-sort-auto-schema.spec.ts b/tests/e2e/graphql-sort-auto-schema.spec.ts index 28f66076b..521ad8c20 100644 --- a/tests/e2e/graphql-sort-auto-schema.spec.ts +++ b/tests/e2e/graphql-sort-auto-schema.spec.ts @@ -1,6 +1,7 @@ import { INestApplication } from '@nestjs/common'; import { Test } from '@nestjs/testing'; -import { printSchema, GraphQLSchema } from 'graphql'; +import { GraphQLSchema } from 'graphql'; +import { printSchema } from '@apollo/federation'; import { FileSystemHelper } from '../../lib/schema-builder/helpers/file-system.helper'; import { sortedPrintedSchemaSnapshot } from '../utils/printed-schema.snapshot'; import { GRAPHQL_SDL_FILE_HEADER } from '../../lib/graphql.constants'; diff --git a/tests/e2e/graphql-sort-schema.spec.ts b/tests/e2e/graphql-sort-schema.spec.ts index 1c0e3975f..c84846a82 100644 --- a/tests/e2e/graphql-sort-schema.spec.ts +++ b/tests/e2e/graphql-sort-schema.spec.ts @@ -1,6 +1,7 @@ import { INestApplication } from '@nestjs/common'; import { Test } from '@nestjs/testing'; -import { printSchema, GraphQLSchema } from 'graphql'; +import { GraphQLSchema } from 'graphql'; +import { printSchema } from '@apollo/federation'; import { SortSchemaModule } from '../graphql/sort-schema.module'; import { GRAPHQL_SDL_FILE_HEADER } from '../../lib/graphql.constants'; import { GraphQLSchemaHost } from '../../lib';