Skip to content

Commit 879950f

Browse files
committed
Move gql driver to its own class/file
1 parent 2ba21e7 commit 879950f

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/core/graphql/driver.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { YogaDriver, YogaDriverConfig } from '@graphql-yoga/nestjs';
2+
import { Injectable } from '@nestjs/common';
3+
import { HttpAdapter } from '../http';
4+
5+
@Injectable()
6+
export class Driver extends YogaDriver<'fastify'> {
7+
constructor(private readonly http: HttpAdapter) {
8+
super();
9+
}
10+
11+
async start(options: YogaDriverConfig<'fastify'>) {
12+
await super.start(options);
13+
14+
// Setup file upload handling
15+
const fastify = this.http.getInstance();
16+
fastify.addContentTypeParser('multipart/form-data', (req, payload, done) =>
17+
done(null),
18+
);
19+
}
20+
}

src/core/graphql/graphql.module.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { YogaDriver } from '@graphql-yoga/nestjs';
21
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
32
import { APP_INTERCEPTOR } from '@nestjs/core';
43
import { GraphQLModule as NestGraphqlModule } from '@nestjs/graphql';
54
import { HttpAdapterHost } from '~/core/http';
65
import { TracingModule } from '../tracing';
6+
import { Driver } from './driver';
77
import { GqlContextHost, GqlContextHostImpl } from './gql-context.host';
88
import { GraphqlErrorFormatter } from './graphql-error-formatter';
99
import { GraphqlLoggingPlugin } from './graphql-logging.plugin';
@@ -29,7 +29,7 @@ export class GraphqlOptionsModule {}
2929
@Module({
3030
imports: [
3131
NestGraphqlModule.forRootAsync({
32-
driver: YogaDriver,
32+
driver: Driver,
3333
useExisting: GraphqlOptions,
3434
imports: [GraphqlOptionsModule],
3535
}),
@@ -51,11 +51,5 @@ export class GraphqlModule implements NestModule {
5151
// Always attach our GQL Context middleware.
5252
// It has its own logic to handle non-gql requests.
5353
consumer.apply(this.middleware.use).forRoutes('*');
54-
55-
// Setup file upload handling
56-
const fastify = this.app.httpAdapter.getInstance();
57-
fastify.addContentTypeParser('multipart/form-data', (req, payload, done) =>
58-
done(null),
59-
);
6054
}
6155
}

0 commit comments

Comments
 (0)