Skip to content

(refactor) Replace federation with subgraph #1813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
23 changes: 10 additions & 13 deletions lib/federation/graphql-federation.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ export class GraphQLFederationFactory {
}

private buildSchemaFromTypeDefs(options: GqlModuleOptions) {
const { buildFederatedSchema } = loadPackage(
'@apollo/federation',
'ApolloFederation',
() => require('@apollo/federation'),
);
const { buildSubgraphSchema }: typeof import('@apollo/subgraph') =
loadPackage('@apollo/subgraph', 'ApolloFederation', () =>
require('@apollo/subgraph'),
);

return buildFederatedSchema([
return buildSubgraphSchema([
{
typeDefs: gql`
${options.typeDefs}
Expand All @@ -92,12 +91,10 @@ export class GraphQLFederationFactory {
private async generateSchema(
options: GqlModuleOptions,
): Promise<GraphQLSchema> {
const { buildFederatedSchema } = loadPackage(
'@apollo/federation',
'ApolloFederation',
() => require('@apollo/federation'),
);
const { printSubgraphSchema } = loadPackage(
const {
buildSubgraphSchema,
printSubgraphSchema,
}: typeof import('@apollo/subgraph') = loadPackage(
'@apollo/subgraph',
'ApolloFederation',
() => require('@apollo/subgraph'),
Expand All @@ -109,7 +106,7 @@ export class GraphQLFederationFactory {
options,
this.resolversExplorerService.getAllCtors(),
);
let executableSchema: GraphQLSchema = buildFederatedSchema({
let executableSchema: GraphQLSchema = buildSubgraphSchema({
typeDefs: gql(printSubgraphSchema(autoGeneratedSchema)),
resolvers: this.getResolvers(options.resolvers),
});
Expand Down
9 changes: 4 additions & 5 deletions lib/federation/graphql-federation.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,10 @@ export class GraphQLFederationModule implements OnModuleInit, OnModuleDestroy {
if (!this.httpAdapterHost || !this.httpAdapterHost.httpAdapter) {
return;
}
const { printSubgraphSchema } = loadPackage(
'@apollo/subgraph',
'ApolloFederation',
() => require('@apollo/subgraph'),
);
const { printSubgraphSchema }: typeof import('@apollo/subgraph') =
loadPackage('@apollo/subgraph', 'ApolloFederation', () =>
require('@apollo/subgraph'),
);

const { typePaths } = this.options;
const typeDefs =
Expand Down
13 changes: 5 additions & 8 deletions lib/graphql-definitions.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,16 @@ export class GraphQLDefinitionsFactory {
const typePathDefs = await this.gqlTypesLoader.mergeTypesByPaths(typePaths);
const mergedTypeDefs = extend(typePathDefs, typeDefs);

const { buildFederatedSchema } = loadPackage(
'@apollo/federation',
'ApolloFederation',
() => require('@apollo/federation'),
);

const { printSubgraphSchema } = loadPackage(
const {
buildSubgraphSchema,
printSubgraphSchema,
}: typeof import('@apollo/subgraph') = loadPackage(
'@apollo/subgraph',
'ApolloFederation',
() => require('@apollo/subgraph'),
);

const schema = buildFederatedSchema([
const schema = buildSubgraphSchema([
{
typeDefs: gql`
${mergedTypeDefs}
Expand Down
4 changes: 3 additions & 1 deletion lib/graphql-schema.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ export class GraphQLSchemaBuilder {
}

private loadFederationDirectives() {
const { federationDirectives } = loadPackage(
const {
federationDirectives,
}: typeof import('@apollo/subgraph/dist/directives') = loadPackage(
'@apollo/subgraph/dist/directives',
'SchemaBuilder',
() => require('@apollo/subgraph/dist/directives'),
Expand Down
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"release": "release-it"
},
"devDependencies": {
"@apollo/federation": "0.33.3",
"@apollo/gateway": "0.42.3",
"@apollo/subgraph": "0.1.2",
"@commitlint/cli": "13.2.1",
Expand Down Expand Up @@ -81,7 +80,6 @@
"ws": "8.2.3"
},
"peerDependencies": {
"@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",
Expand All @@ -94,9 +92,6 @@
"ts-morph": "^11.0.3 || ^12.0.0"
},
"peerDependenciesMeta": {
"@apollo/federation": {
"optional": true
},
"@apollo/gateway": {
"optional": true
},
Expand Down