Skip to content

Commit

Permalink
docs: nestjs federation subgraph + gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Apr 29, 2024
1 parent 789e53b commit e6549b6
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions website/src/pages/docs/integrations/integration-with-nestjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,66 @@ Federation Gateways and Services through the `YogaGatewayDriver` and `YogaFedera
npm i @nestjs/graphql @graphql-yoga/nestjs-federation graphql-yoga graphql
```

### Create Application Module
#### Subgraph

For the subgraph we use the `YogaFederationDriver` and `YogaFederationDriverConfig`.

```typescript
import { YogaFederationDriver, YogaFederationDriverConfig } from '@graphql-yoga/nestjs-federation'
import { Module } from '@nestjs/common'
import { GraphQLModule } from '@nestjs/graphql'
import { DeprecatedProductsResolver } from './deprecated-products.resolver'
import { InventoryResolver } from './inventory.resolver'
import { ProductResearchResolver } from './product-research.resolver'
import { ProductsResolver } from './products.resolver'
import { UsersResolver } from './users.resolver'

@Module({
imports: [
GraphQLModule.forRoot<YogaFederationDriverConfig>({
driver: YogaFederationDriver,
typePaths: ['**/*.graphql']
})
],
providers: [
UsersResolver,
ProductsResolver,
ProductResearchResolver,
DeprecatedProductsResolver,
InventoryResolver
]
})
export class AppModule {}
```

### Develop GraphQL
#### Gateway

For the gateway we use the `YogaGatewayDriver` and `YogaGatewayDriverConfig`.

```typescript
import { YogaGatewayDriver, YogaGatewayDriverConfig } from '@graphql-yoga/nestjs-federation'
import { Module } from '@nestjs/common'
import { GraphQLModule } from '@nestjs/graphql'

@Module({
imports: [
GraphQLModule.forRoot<YogaGatewayDriverConfig>({
driver: YogaGatewayDriver,
gateway: {
services: [{ name: 'subgraph', url: 'http://subgraph/graphql' }]
}
})
]
})
export class AppModule {}
```

### Further development

This is just a federation and gateway driver; meaning, everything else should work as
Yoga offers just a federation and gateway driver; meaning, everything else works as
[showcased in NestJS federation documentation](https://docs.nestjs.com/graphql/federation).

<Callout>
A complete example, with full Apollo Federation Subgraph Compatibility, [is available in the
A complete example of a Apollo Federation Subgraph, [is available in the
repository](https://github.com/dotansimha/graphql-yoga/tree/main/examples/nestjs-apollo-federation-compatibility).
</Callout>

0 comments on commit e6549b6

Please sign in to comment.