From a2dbb4ad0490e80f2c4f81325052dd1d75afe916 Mon Sep 17 00:00:00 2001 From: Ian Mobley Date: Sat, 16 Oct 2021 09:29:06 -0700 Subject: [PATCH 1/4] chore(deps) Bump federation and add subgraph Recently the subgraph package was split off from the main federation package. This moved the federation directives and renamed printSchema to printSubgraphSchema. --- package-lock.json | 47 +++++++++++++++++++++++++++++++++++++++-------- package.json | 9 +++++++-- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 96143085a..4334d41b9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,8 +25,9 @@ "ws": "8.2.2" }, "devDependencies": { - "@apollo/federation": "0.33.0", + "@apollo/federation": "^0.33.3", "@apollo/gateway": "0.42.0", + "@apollo/subgraph": "^0.1.2", "@commitlint/cli": "13.2.1", "@commitlint/config-angular": "13.2.0", "@nestjs/common": "8.1.1", @@ -70,8 +71,9 @@ "typescript": "4.4.4" }, "peerDependencies": { - "@apollo/federation": "^0.26.0 || ^0.27.0 || ^0.29.0 || 0.33.0", + "@apollo/federation": "^0.26.0 || ^0.27.0 || ^0.29.0 || ^0.33.0", "@apollo/gateway": "^0.29.0 || ^0.32.0 || ^0.33.0 || ^0.35.0 || ^0.38.0 || ^0.42.0", + "@apollo/subgraph": "^0.1.2", "@nestjs/common": "^8.0.0", "@nestjs/core": "^8.0.0", "apollo-server-core": "^3.0.0", @@ -88,6 +90,9 @@ "@apollo/gateway": { "optional": true }, + "@apollo/subgraph": { + "optional": true + }, "apollo-server-core": { "optional": true }, @@ -116,11 +121,12 @@ } }, "node_modules/@apollo/federation": { - "version": "0.33.0", - "resolved": "https://registry.npmjs.org/@apollo/federation/-/federation-0.33.0.tgz", - "integrity": "sha512-Zywqb6Zv12/PVl7K/jtDgcJFghg02fqqDHyGbHBhf0+WdNvI9QqRvOY433BuZw/NYcRUbz9cPEAG5JCRB2K83w==", + "version": "0.33.3", + "resolved": "https://registry.npmjs.org/@apollo/federation/-/federation-0.33.3.tgz", + "integrity": "sha512-+BRJW1Kf7im86CWPQEdocXQTyPUH132MMoMCXuRvM4F1idb5EldqRkFNM8y9IAYNnbHsthmIWlrqmkuYg+irGQ==", "dev": true, "dependencies": { + "@apollo/subgraph": "^0.1.2", "apollo-graphql": "^0.9.3", "apollo-server-types": "^3.0.2", "lodash.xorby": "^4.7.0" @@ -283,6 +289,21 @@ "node": ">=8" } }, + "node_modules/@apollo/subgraph": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@apollo/subgraph/-/subgraph-0.1.2.tgz", + "integrity": "sha512-vrPtpayvJkLdqc/iLjhXi+W9HQ+Avnb2a8ylaZb0lsm9p0y1H5QxNDhC3SHhdYRvBnNeqgxE+OGYG1rHldMQIQ==", + "dev": true, + "dependencies": { + "apollo-graphql": "^0.9.3" + }, + "engines": { + "node": ">=12.13.0 <17.0" + }, + "peerDependencies": { + "graphql": "^15.5.3" + } + }, "node_modules/@apollographql/apollo-tools": { "version": "0.5.1", "integrity": "sha512-ZII+/xUFfb9ezDU2gad114+zScxVFMVlZ91f8fGApMzlS1kkqoyLnC4AJaQ1Ya/X+b63I20B4Gd+eCL8QuB4sA==", @@ -16484,11 +16505,12 @@ "requires": {} }, "@apollo/federation": { - "version": "0.33.0", - "resolved": "https://registry.npmjs.org/@apollo/federation/-/federation-0.33.0.tgz", - "integrity": "sha512-Zywqb6Zv12/PVl7K/jtDgcJFghg02fqqDHyGbHBhf0+WdNvI9QqRvOY433BuZw/NYcRUbz9cPEAG5JCRB2K83w==", + "version": "0.33.3", + "resolved": "https://registry.npmjs.org/@apollo/federation/-/federation-0.33.3.tgz", + "integrity": "sha512-+BRJW1Kf7im86CWPQEdocXQTyPUH132MMoMCXuRvM4F1idb5EldqRkFNM8y9IAYNnbHsthmIWlrqmkuYg+irGQ==", "dev": true, "requires": { + "@apollo/subgraph": "^0.1.2", "apollo-graphql": "^0.9.3", "apollo-server-types": "^3.0.2", "lodash.xorby": "^4.7.0" @@ -16613,6 +16635,15 @@ } } }, + "@apollo/subgraph": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@apollo/subgraph/-/subgraph-0.1.2.tgz", + "integrity": "sha512-vrPtpayvJkLdqc/iLjhXi+W9HQ+Avnb2a8ylaZb0lsm9p0y1H5QxNDhC3SHhdYRvBnNeqgxE+OGYG1rHldMQIQ==", + "dev": true, + "requires": { + "apollo-graphql": "^0.9.3" + } + }, "@apollographql/apollo-tools": { "version": "0.5.1", "integrity": "sha512-ZII+/xUFfb9ezDU2gad114+zScxVFMVlZ91f8fGApMzlS1kkqoyLnC4AJaQ1Ya/X+b63I20B4Gd+eCL8QuB4sA==", diff --git a/package.json b/package.json index a9c2065ac..be9fcbf73 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,9 @@ "release": "release-it" }, "devDependencies": { - "@apollo/federation": "0.33.0", + "@apollo/federation": "^0.33.3", "@apollo/gateway": "0.42.0", + "@apollo/subgraph": "^0.1.2", "@commitlint/cli": "13.2.1", "@commitlint/config-angular": "13.2.0", "@nestjs/common": "8.1.1", @@ -80,8 +81,9 @@ "ws": "8.2.2" }, "peerDependencies": { - "@apollo/federation": "^0.26.0 || ^0.27.0 || ^0.29.0 || 0.33.0", + "@apollo/federation": "^0.26.0 || ^0.27.0 || ^0.29.0 || ^0.33.0", "@apollo/gateway": "^0.29.0 || ^0.32.0 || ^0.33.0 || ^0.35.0 || ^0.38.0 || ^0.42.0", + "@apollo/subgraph": "^0.1.2", "@nestjs/common": "^8.0.0", "@nestjs/core": "^8.0.0", "apollo-server-core": "^3.0.0", @@ -98,6 +100,9 @@ "@apollo/gateway": { "optional": true }, + "@apollo/subgraph": { + "optional": true + }, "apollo-server-core": { "optional": true }, From 827556cb95697eff2e6a8a142e47f1c27b608229 Mon Sep 17 00:00:00 2001 From: Ian Mobley Date: Sat, 16 Oct 2021 09:30:54 -0700 Subject: [PATCH 2/4] fix(deps) Replace use of federation directives This is now part of the subgraph dependency. --- lib/graphql-schema.builder.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/graphql-schema.builder.ts b/lib/graphql-schema.builder.ts index 4ad6a0102..b0b6d6d38 100644 --- a/lib/graphql-schema.builder.ts +++ b/lib/graphql-schema.builder.ts @@ -116,9 +116,9 @@ export class GraphQLSchemaBuilder { private loadFederationDirectives() { const { federationDirectives } = loadPackage( - '@apollo/federation/dist/directives', + '@apollo/subgraph/dist/directives', 'SchemaBuilder', - () => require('@apollo/federation/dist/directives'), + () => require('@apollo/subgraph/dist/directives'), ); return federationDirectives; } From bf088f1eb5888fb78b3d6b9e83db2acb4255bc61 Mon Sep 17 00:00:00 2001 From: Ian Mobley Date: Sat, 16 Oct 2021 09:32:06 -0700 Subject: [PATCH 3/4] fix(deps) Replace uses of printSchema This is now part of the subgraph dependency and renamed to printSubgraphSchema. --- lib/federation/graphql-federation.factory.ts | 27 ++++++++++++-------- lib/federation/graphql-federation.module.ts | 8 +++--- lib/graphql-definitions.factory.ts | 17 +++++++----- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/lib/federation/graphql-federation.factory.ts b/lib/federation/graphql-federation.factory.ts index 482eb5286..4999169d3 100644 --- a/lib/federation/graphql-federation.factory.ts +++ b/lib/federation/graphql-federation.factory.ts @@ -92,20 +92,25 @@ export class GraphQLFederationFactory { private async generateSchema( options: GqlModuleOptions, ): Promise { - const { - buildFederatedSchema, - printSchema, - } = loadPackage('@apollo/federation', 'ApolloFederation', () => - require('@apollo/federation'), + const { buildFederatedSchema } = loadPackage( + '@apollo/federation', + 'ApolloFederation', + () => require('@apollo/federation'), ); - - const autoGeneratedSchema: GraphQLSchema = await this.gqlSchemaBuilder.buildFederatedSchema( - options.autoSchemaFile, - options, - this.resolversExplorerService.getAllCtors(), + const { printSubgraphSchema } = loadPackage( + '@apollo/subgraph', + 'ApolloFederation', + () => require('@apollo/subgraph'), ); + + const autoGeneratedSchema: GraphQLSchema = + await this.gqlSchemaBuilder.buildFederatedSchema( + options.autoSchemaFile, + options, + this.resolversExplorerService.getAllCtors(), + ); let executableSchema: GraphQLSchema = buildFederatedSchema({ - typeDefs: gql(printSchema(autoGeneratedSchema)), + typeDefs: gql(printSubgraphSchema(autoGeneratedSchema)), resolvers: this.getResolvers(options.resolvers), }); diff --git a/lib/federation/graphql-federation.module.ts b/lib/federation/graphql-federation.module.ts index ca2dd4f18..fb787d13e 100644 --- a/lib/federation/graphql-federation.module.ts +++ b/lib/federation/graphql-federation.module.ts @@ -142,10 +142,10 @@ export class GraphQLFederationModule implements OnModuleInit, OnModuleDestroy { if (!this.httpAdapterHost || !this.httpAdapterHost.httpAdapter) { return; } - const { printSchema } = loadPackage( - '@apollo/federation', + const { printSubgraphSchema } = loadPackage( + '@apollo/subgraph', 'ApolloFederation', - () => require('@apollo/federation'), + () => require('@apollo/subgraph'), ); const { typePaths } = this.options; @@ -161,7 +161,7 @@ export class GraphQLFederationModule implements OnModuleInit, OnModuleDestroy { if (this.options.definitions && this.options.definitions.path) { await this.graphqlFactory.generateDefinitions( - printSchema(apolloOptions.schema), + printSubgraphSchema(apolloOptions.schema), this.options, ); } diff --git a/lib/graphql-definitions.factory.ts b/lib/graphql-definitions.factory.ts index 668642e7a..70eac197f 100644 --- a/lib/graphql-definitions.factory.ts +++ b/lib/graphql-definitions.factory.ts @@ -116,11 +116,16 @@ export class GraphQLDefinitionsFactory { const typePathDefs = await this.gqlTypesLoader.mergeTypesByPaths(typePaths); const mergedTypeDefs = extend(typePathDefs, typeDefs); - const { - buildFederatedSchema, - printSchema, - } = loadPackage('@apollo/federation', 'ApolloFederation', () => - require('@apollo/federation'), + const { buildFederatedSchema } = loadPackage( + '@apollo/federation', + 'ApolloFederation', + () => require('@apollo/federation'), + ); + + const { printSubgraphSchema } = loadPackage( + '@apollo/subgraph', + 'ApolloFederation', + () => require('@apollo/subgraph'), ); const schema = buildFederatedSchema([ @@ -133,7 +138,7 @@ export class GraphQLDefinitionsFactory { ]); const tsFile = await this.gqlAstExplorer.explore( gql` - ${printSchema(schema)} + ${printSubgraphSchema(schema)} `, path, outputAs, From 6982a85441dbd0fce832aecd6821d392ee7babb1 Mon Sep 17 00:00:00 2001 From: Ian Mobley Date: Sat, 16 Oct 2021 09:32:33 -0700 Subject: [PATCH 4/4] fix(deps) Replace schemaExtensions This is now part of the subgraph dependency and the type defs do not need to be duplicated. --- lib/utils/transform-schema.util.ts | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/lib/utils/transform-schema.util.ts b/lib/utils/transform-schema.util.ts index 593b2f8ee..24b8f30df 100644 --- a/lib/utils/transform-schema.util.ts +++ b/lib/utils/transform-schema.util.ts @@ -2,7 +2,7 @@ // The changed lines are 31-40 and 85-87 and the original file can be found here: // https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo-graphql/src/schema/transformSchema.ts -import { GraphQLReferenceResolver } from '@apollo/federation/dist/types'; +import '@apollo/subgraph/dist/schemaExtensions'; import { GraphQLFieldConfigArgumentMap, GraphQLFieldConfigMap, @@ -27,17 +27,6 @@ import { isUnionType, } from 'graphql'; -// Definitions taken from here: https://github.com/apollographql/apollo-server/blob/main/packages/apollo-federation/src/types.ts#L62 -declare module 'graphql/type/definition' { - interface GraphQLObjectType { - resolveReference?: GraphQLReferenceResolver; - } - - interface GraphQLObjectTypeConfig { - resolveReference?: GraphQLReferenceResolver; - } -} - type TypeTransformer = ( type: GraphQLNamedType, ) => GraphQLNamedType | null | undefined;