8000 Merge pull request #1797 from iMobs/upgrade-apollo-federation-with-su… · nestjs/graphql@0af4f4a · GitHub
[go: up one dir, main page]

Skip to content

Commit 0af4f4a

Browse files
Merge pull request #1797 from iMobs/upgrade-apollo-federation-with-subgraph
fix(deps) Upgrade apollo federation with subgraph
2 parents a64645e + 6982a85 commit 0af4f4a

7 files changed

+80
-45
lines changed

lib/federation/graphql-federation.factory.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,25 @@ export class GraphQLFederationFactory {
9292
private async generateSchema(
9393
options: GqlModuleOptions,
9494
): Promise<GraphQLSchema> {
95-
const {
96-
buildFederatedSchema,
97-
printSchema,
98-
} = loadPackage('@apollo/federation', 'ApolloFederation', () =>
99-
require('@apollo/federation'),
95+
const { buildFederatedSchema } = loadPackage(
96+
'@apollo/federation',
97+
'ApolloFederation',
98+
() => require('@apollo/federation'),
10099
);
101-
102-
const autoGeneratedSchema: GraphQLSchema = await this.gqlSchemaBuilder.buildFederatedSchema(
103-
options.autoSchemaFile,
104-
options,
105-
this.resolversExplorerService.getAllCtors(),
100+
const { printSubgraphSchema } = loadPackage(
101+
'@apollo/subgraph',
102+
'ApolloFederation',
103+
() => require('@apollo/subgraph'),
106104
);
105+
106+
const autoGeneratedSchema: GraphQLSchema =
107+
await this.gqlSchemaBuilder.buildFederatedSchema(
108+
options.autoSchemaFile,
109+
options,
110+
this.resolversExplorerService.getAllCtors(),
111+
);
107112
let executableSchema: GraphQLSchema = buildFederatedSchema({
108-
typeDefs: gql(printSchema(autoGeneratedSchema)),
113+
typeDefs: gql(printSubgraphSchema(autoGeneratedSchema)),
109114
resolvers: this.getResolvers(options.resolvers),
110115
});
111116

lib/federation/graphql-federation.module.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ export class GraphQLFederationModule implements OnModuleInit, OnModuleDestroy {
142142
if (!this.httpAdapterHost || !this.httpAdapterHost.httpAdapter) {
143143
return;
144144
}
145-
const { printSchema } = loadPackage(
146-
'@apollo/federation',
145+
const { printSubgraphSchema } = loadPackage(
146+
'@apollo/subgraph',
147147
'ApolloFederation',
148-
() => require('@apollo/federation'),
148+
() => require('@apollo/subgraph'),
149149
);
150150

151151
const { typePaths } = this.options;
@@ -161,7 +161,7 @@ export class GraphQLFederationModule implements OnModuleInit, OnModuleDestroy {
161161

162162
if (this.options.definitions && this.options.definitions.path) {
163163
await this.graphqlFactory.generateDefinitions(
164-
printSchema(apolloOptions.schema),
164+
printSubgraphSchema(apolloOptions.schema),
165165
this.options,
166166
);
167167
}

lib/graphql-definitions.factory.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,16 @@ export class GraphQLDefinitionsFactory {
116116
const typePathDefs = await this.gqlTypesLoader.mergeTypesByPaths(typePaths);
117117
const mergedTypeDefs = extend(typePathDefs, typeDefs);
118118

119-
const {
120-
buildFederatedSchema,
121-
printSchema,
122-
} = loadPackage('@apollo/federation', 'ApolloFederation', () =>
123-
require('@apollo/federation'),
119+
const { buildFederatedSchema } = loadPackage(
120+
'@apollo/federation',
121+
'ApolloFederation',
122+
() => require('@apollo/federation'),
123+
);
124+
125+
const { printSubgraphSchema } = loadPackage(
126+
'@apollo/subgraph',
127+
'ApolloFederation',
128+
() => require('@apollo/subgraph'),
124129
);
125130

126131
const schema = buildFederatedSchema([
@@ -133,7 +138,7 @@ export class GraphQLDefinitionsFactory {
133138
]);
134139
const tsFile = await this.gqlAstExplorer.explore(
135140
gql`
136-
${printSchema(schema)}
141+
${printSubgraphSchema(schema)}
137142
`,
138143
path,
139144
outputAs,

lib/graphql-schema.builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ export class GraphQLSchemaBuilder {
116116

117117
private loadFederationDirectives() {
118118
const { federationDirectives } = loadPackage(
119-
'@apollo/federation/dist/directives',
119+
'@apollo/subgraph/dist/directives',
120120
'SchemaBuilder',
121-
() => require('@apollo/federation/dist/directives'),
121+
() => require('@apollo/subgraph/dist/directives'),
122122
);
123123
return federationDirectives;
124124
}

lib/utils/transform-schema.util.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// The changed lines are 31-40 and 85-87 and the original file can be found here:
33
// https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo-graphql/src/schema/transformSchema.ts
44

5-
import { GraphQLReferenceResolver } from '@apollo/federation/dist/types';
5+
import '@apollo/subgraph/dist/schemaExtensions';
66
import {
77
GraphQLFieldConfigArgumentMap,
88
GraphQLFieldConfigMap,
@@ -27,17 +27,6 @@ import {
2727
isUnionType,
2828
} from 'graphql';
2929

30-
// Definitions taken from here: https://github.com/apollographql/apollo-server/blob/main/packages/apollo-federation/src/types.ts#L62
31-
declare module 'graphql/type/definition' {
32-
interface GraphQLObjectType {
33-
resolveReference?: GraphQLReferenceResolver<any>;
34-
}
35-
36-
interface GraphQLObjectTypeConfig<TSource, TContext> {
37-
resolveReference?: GraphQLReferenceResolver<TContext>;
38-
}
39-
}
40-
4130
type TypeTransformer = (
4231
type: GraphQLNamedType,
4332
) => GraphQLNamedType | null | undefined;

package-lock.json

Lines changed: 39 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
"release": "release-it"
2020
},
2121
"devDependencies": {
22-
"@apollo/federation": "0.33.0",
22+
"@apollo/federation": "^0.33.3",
2323
"@apollo/gateway": "0.42.0",
24+
"@apollo/subgraph": "^0.1.2",
2425
"@commitlint/cli": "13.2.1",
2526
"@commitlint/config-angular": "13.2.0",
2627
"@nestjs/common": "8.1.1",
@@ -80,8 +81,9 @@
8081
"ws": "8.2.3"
8182
},
8283
"peerDependencies": {
83-
"@apollo/federation": "^0.26.0 || ^0.27.0 || ^0.29.0 || 0.33.0",
84+
"@apollo/federation": "^0.26.0 || ^0.27.0 || ^0.29.0 || ^0.33.0",
8485
"@apollo/gateway": "^0.29.0 || ^0.32.0 || ^0.33.0 || ^0.35.0 || ^0.38.0 || ^0.42.0",
86+
"@apollo/subgraph": "^0.1.2",
8587
"@nestjs/common": "^8.0.0",
8688
"@nestjs/core": "^8.0.0",
8789
"apollo-server-core": "^3.0.0",
@@ -98,6 +100,9 @@
98100
"@apollo/gateway": {
99101
"optional": true
100102
},
103+
"@apollo/subgraph": {
104+
"optional": true
105+
},
101106
"apollo-server-core": {
102107
"optional": true
103108
},

0 commit comments

Comments
 (0)
0