Skip to content
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

feat: ✨ Federated gateway #18

Merged
merged 4 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"cSpell.words": [
"nestjs"
"nestjs",
"supergraph"
]
}
15 changes: 14 additions & 1 deletion apps/gateway/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { IntrospectAndCompose } from '@apollo/gateway';
import { ApolloGatewayDriver, ApolloGatewayDriverConfig } from '@nestjs/apollo';
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { subgraphsConfig } from '@graphql-federation-workspace/applications-config';

import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
imports: [],
imports: [
GraphQLModule.forRoot<ApolloGatewayDriverConfig>({
driver: ApolloGatewayDriver,
gateway: {
supergraphSdl: new IntrospectAndCompose({
subgraphs: subgraphsConfig,
}),
zhumeisongsong marked this conversation as resolved.
Show resolved Hide resolved
},
}),
],
zhumeisongsong marked this conversation as resolved.
Show resolved Hide resolved
controllers: [AppController],
providers: [AppService],
})
Expand Down
4 changes: 1 addition & 3 deletions apps/gateway/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ async function bootstrap() {
const port = gatewayConfig.port;

await app.listen(port);
Logger.log(
`🚀 Application is running on: http://${gatewayConfig.host}:${port}`
);
Logger.log(`🚀 Application is running on: ${gatewayConfig.host}:${port}`);
}

bootstrap();
4 changes: 1 addition & 3 deletions apps/users-application/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ async function bootstrap() {
const port = userSubGraph.port;

await app.listen(port);
Logger.log(
`🚀 Application is running on: http://${userSubGraph.host}:${port}`
);
Logger.log(`🚀 Application is running on: ${userSubGraph.host}:${port}`);
}

bootstrap();
1 change: 1 addition & 0 deletions libs/application-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './lib/applications-config';
export * from './lib/subgraphs-config';
4 changes: 4 additions & 0 deletions libs/application-config/src/lib/applications-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
interface ApplicationConfig {
host: string;
port: string;
name: string;
}

const DEFAULT_HOST = 'localhost';
Expand All @@ -15,15 +16,18 @@ const DEFAULT_PORT = {
export const gatewayConfig: ApplicationConfig = {
host: process.env['GATEWAY_HOST'] ?? DEFAULT_HOST,
port: process.env['GATEWAY_PORT'] ?? DEFAULT_PORT.gateway,
name: 'gateway',
};

// Graphql
export const userSubGraph: ApplicationConfig = {
host: process.env['USER_HOST'] ?? DEFAULT_HOST,
port: process.env['USER_PORT'] ?? DEFAULT_PORT.user,
name: 'user',
};

export const taskSubGraph: ApplicationConfig = {
host: process.env['TASK_HOST'] ?? DEFAULT_HOST,
port: process.env['TASK_PORT'] ?? DEFAULT_PORT.task,
name: 'task',
};
10 changes: 10 additions & 0 deletions libs/application-config/src/lib/subgraphs-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ServiceEndpointDefinition } from '@apollo/gateway';

import { userSubGraph } from './applications-config';

export const subgraphsConfig: ServiceEndpointDefinition[] = [
{
name: userSubGraph.name,
url: `${userSubGraph.host}:${userSubGraph.port}/graphql`,
},
];
zhumeisongsong marked this conversation as resolved.
Show resolved Hide resolved
Loading