Skip to content

Commit

Permalink
Federation v2 (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Oct 6, 2023
2 parents 68f325a + d96f9a3 commit c8273f8
Show file tree
Hide file tree
Showing 65 changed files with 7,287 additions and 868 deletions.
23 changes: 23 additions & 0 deletions examples/federation-v2/graphql-gateway/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { IntrospectAndCompose } from '@apollo/gateway'
import { ApolloGatewayDriver, ApolloGatewayDriverConfig } from '@nestjs/apollo'
import { Module } from '@nestjs/common'
import { GraphQLModule } from '@nestjs/graphql'

@Module({
imports: [
GraphQLModule.forRoot<ApolloGatewayDriverConfig>({
driver: ApolloGatewayDriver,
gateway: {
supergraphSdl: new IntrospectAndCompose({
subgraphs: [
{ name: 'todo-items', url: 'http://localhost:3001/graphql' },
{ name: 'sub-tasks', url: 'http://localhost:3002/graphql' },
{ name: 'tags', url: 'http://localhost:3003/graphql' },
{ name: 'user', url: 'http://localhost:3004/graphql' }
]
})
}
})
]
})
export class AppModule {}
23 changes: 23 additions & 0 deletions examples/federation-v2/graphql-gateway/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ValidationPipe } from '@nestjs/common'
import { NestFactory } from '@nestjs/core'

import { AppModule } from './app.module'

async function bootstrap(): Promise<void> {
const app = await NestFactory.create(AppModule)

app.useGlobalPipes(
new ValidationPipe({
transform: true,
whitelist: true,
forbidNonWhitelisted: true,
skipMissingProperties: false,
forbidUnknownValues: true
})
)

await app.listen(3000)
}

// eslint-disable-next-line no-void
void bootstrap()
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export const todoItemFields = `
id
`

export const subTaskFields = `
id
title
description
completed
todoItemId
`

export const pageInfoField = `
pageInfo{
hasNextPage
hasPreviousPage
startCursor
endCursor
}
`

export const edgeNodes = (fields: string): string => `
edges {
node{
${fields}
}
cursor
}
`
34 changes: 34 additions & 0 deletions examples/federation-v2/sub-task-graphql/e2e/__fixtures__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Connection } from 'typeorm'

import { executeTruncate } from '../../../../helpers'
import { SubTaskEntity } from '../../src/sub-task/sub-task.entity'

const tables = ['sub_task']
export const truncate = async (connection: Connection): Promise<void> => executeTruncate(connection, tables)

export const refresh = async (connection: Connection): Promise<void> => {
await truncate(connection)

const todoItems = [
{ id: 1, title: 'Create Nest App' },
{ id: 2, title: 'Create Entity' },
{ id: 3, title: 'Create Entity Service' },
{ id: 4, title: 'Add Todo Item Resolver' },
{ id: 5, title: 'How to create item With Sub Tasks' }
]
const subTaskRepo = connection.getRepository(SubTaskEntity)

await subTaskRepo.save(
todoItems.reduce(
(subTasks, todo) => [
...subTasks,
{ completed: true, title: `${todo.title} - Sub Task 1`, todoItemId: todo.id },
{ completed: false, title: `${todo.title} - Sub Task 2`, todoItemId: todo.id },
{ completed: false, title: `${todo.title} - Sub Task 3`, todoItemId: todo.id }
],
[] as Partial<SubTaskEntity>[]
)
)
}

export * from './graphql-fragments'
Loading

0 comments on commit c8273f8

Please sign in to comment.