Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/graphql/lib/federation/graphql-federation.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ export class GraphQLFederationFactory {
options: T,
resolvers: Function[],
) {
const { printSubgraphSchema } = loadPackage(
'@apollo/subgraph',
'ApolloFederation',
() => require('@apollo/subgraph'),
);

const scalarsMap = this.scalarsExplorerService.getScalarsMap();
try {
const buildSchemaOptions = options.buildSchemaOptions || {};
Expand All @@ -298,6 +304,7 @@ export class GraphQLFederationFactory {
},
options.sortSchema,
options.transformAutoSchemaFile && options.transformSchema,
printSubgraphSchema,
);
} catch (err) {
if (err && err.details) {
Expand Down
22 changes: 14 additions & 8 deletions packages/graphql/lib/graphql-schema.builder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Injectable } from '@nestjs/common';
import { isString } from '@nestjs/common/utils/shared.utils';
import { GraphQLSchema, lexicographicSortSchema, printSchema } from 'graphql';
import {
GraphQLSchema,
lexicographicSortSchema,
printSchema as gqlPrintSchema,
} from 'graphql';
import { resolve } from 'path';
import { GRAPHQL_SDL_FILE_HEADER } from './graphql.constants';
import { GqlModuleOptions } from './interfaces';
Expand Down Expand Up @@ -51,6 +55,7 @@ export class GraphQLSchemaBuilder {
transformSchema?: (
schema: GraphQLSchema,
) => GraphQLSchema | Promise<GraphQLSchema>,
printSchema?: (schema: GraphQLSchema) => string,
): Promise<GraphQLSchema> {
const schema = await this.gqlSchemaFactory.create(resolvers, options);
if (typeof autoSchemaFile !== 'boolean') {
Expand All @@ -61,13 +66,14 @@ export class GraphQLSchemaBuilder {
const transformedSchema = transformSchema
? await transformSchema(schema)
: schema;
const fileContent =
GRAPHQL_SDL_FILE_HEADER +
printSchema(
sortSchema
? lexicographicSortSchema(transformedSchema)
: transformedSchema,
);

const base = sortSchema
? lexicographicSortSchema(transformedSchema)
: transformedSchema;

const gql = printSchema ? printSchema(base) : gqlPrintSchema(base);

const fileContent = GRAPHQL_SDL_FILE_HEADER + gql;
await this.fileSystemHelper.writeFile(filename, fileContent);
}
return schema;
Expand Down