You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-16Lines changed: 15 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,6 +43,7 @@ import { authChecker } from "./auth";
43
43
@Module({
44
44
imports: [
45
45
TypeGraphQLModule.forRoot({
46
+
driver: ApolloDriver,
46
47
emitSchemaFile: true,
47
48
validate: false,
48
49
authChecker,
@@ -112,6 +113,7 @@ Example of using the config service to generate `TypeGraphQLModule` options:
112
113
TypeGraphQLModule.forRootAsync({
113
114
inject: [ConfigService],
114
115
useFactory: async (config:ConfigService) => ({
116
+
driver: ApolloDriver,
115
117
cors: true,
116
118
debug: config.isDevelopmentMode,
117
119
playground: !config.isDevelopmentMode,
@@ -126,13 +128,13 @@ Example of using the config service to generate `TypeGraphQLModule` options:
126
128
exportdefaultclassAppModule {}
127
129
```
128
130
129
-
### `TypeGraphQLFederationModule`
131
+
### Apollo Federation
130
132
131
133
`typegraphql-nestjs` has also support for [Apollo Federation](https://www.apollographql.com/docs/federation/).
132
134
133
-
However, Apollo Federation requires building a federated GraphQL schema, hence you need to use the `TypeGraphQLFederationModule` module, designed specially for that case.
135
+
However, Apollo Federation requires building a federated GraphQL schema, hence you need to adjust your code a bit.
134
136
135
-
The usage is really similar to the basic `TypeGraphQLModule` - the only different is that `.forFeature()` method has an option to provide `referenceResolvers` object which is needed in some cases of Apollo Federation:
137
+
The usage is really similar to the basic case - the only difference is that in `TypeGraphQLModule.forFeature()` method you can provide a `referenceResolvers`option object, which is needed in some cases of Apollo Federation:
136
138
137
139
```ts
138
140
function resolveUserReference(
@@ -143,7 +145,7 @@ function resolveUserReference(
143
145
144
146
@Module({
145
147
imports: [
146
-
TypeGraphQLFederationModule.forFeature({
148
+
TypeGraphQLModule.forFeature({
147
149
orphanedTypes: [User],
148
150
referenceResolvers: {
149
151
User: {
@@ -157,25 +159,22 @@ function resolveUserReference(
157
159
exportdefaultclassAccountModule {}
158
160
```
159
161
160
-
The `.forRoot()` method has no differences but you should provide the `skipCheck: true` option as federated schema can violate the standard GraphQL schema rules like at least one query defined:
162
+
For the `.forRoot()` method there's no differences - just need to provide `driver: ApolloFederationDriver` option in order to build a subgraph schema, same as with `GraphQLModule` from `@nestjs/graphql` described in the [NestJS docs](https://docs.nestjs.com/graphql/federation). However, you also need to explicitly setup federation version, by using `federationVersion` option:
161
163
162
164
```ts
163
165
@Module({
164
166
imports: [
165
-
TypeGraphQLFederationModule.forRoot({
166
-
validate: false,
167
-
skipCheck: true,
167
+
TypeGraphQLModule.forRoot({
168
+
driver: ApolloFederationDriver,
169
+
federationVersion: 2,
168
170
}),
169
171
AccountModule,
170
172
],
171
173
})
172
174
exportdefaultclassAppModule {}
173
175
```
174
176
175
-
> Be aware that you cannot mix `TypeGraphQLFederationModule.forRoot()` with the base `TypeGraphQLModule.forFeature()` one.
176
-
> You need to consistently use only `TypeGraphQLFederationModule` across all modules.
177
-
178
-
Then, for exposing the federated schema using Apollo Gateway, you should use the standard NestJS [GraphQLGatewayModule](https://docs.nestjs.com/graphql/federation#federated-example-gateway).
177
+
Then, for exposing the federated schema using Apollo Gateway, you should use the standard [NestJS `ApolloGatewayDriver` solution](https://docs.nestjs.com/graphql/federation#federated-example-gateway).
179
178
180
179
## Caveats
181
180
@@ -201,13 +200,13 @@ You can see some examples of the integration in this repo:
201
200
202
201
Usage of request scoped dependencies - retrieving fresh instances of resolver and service classes on every request (query/mutation)
0 commit comments