File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { DiscoveryService } from '@golevelup/nestjs-discovery' ;
1
2
import { YogaDriver , YogaDriverConfig } from '@graphql-yoga/nestjs' ;
2
3
import { Injectable } from '@nestjs/common' ;
3
4
import { HttpAdapter } from '../http' ;
5
+ import { Plugin } from './plugin.decorator' ;
4
6
5
7
@Injectable ( )
6
8
export class Driver extends YogaDriver < 'fastify' > {
7
- constructor ( private readonly http : HttpAdapter ) {
9
+ constructor (
10
+ private readonly discovery : DiscoveryService ,
11
+ private readonly http : HttpAdapter ,
12
+ ) {
8
13
super ( ) ;
9
14
}
10
15
11
16
async start ( options : YogaDriverConfig < 'fastify' > ) {
17
+ // Do our plugin discovery / registration
18
+ const discoveredPlugins = await this . discovery . providersWithMetaAtKey (
19
+ Plugin . KEY ,
20
+ ) ;
21
+ options . plugins = [
22
+ ...( options . plugins ?? [ ] ) ,
23
+ ...discoveredPlugins . map ( ( cls ) => cls . discoveredClass . instance ) ,
24
+ ] ;
25
+
12
26
await super . start ( options ) ;
13
27
14
28
// Setup file upload handling
Original file line number Diff line number Diff line change 4
4
isGqlContext ,
5
5
NotGraphQLContext ,
6
6
} from './gql-context.host' ;
7
+ export * from './plugin.decorator' ;
Original file line number Diff line number Diff line change
1
+ import { YogaDriverServerContext } from '@graphql-yoga/nestjs' ;
2
+ import { createMetadataDecorator } from '@seedcompany/nest' ;
3
+ import { Plugin as PluginNoContext } from 'graphql-yoga' ;
4
+ import { GqlContextType } from '~/common' ;
5
+
6
+ export const Plugin = createMetadataDecorator ( {
7
+ types : [ 'class' ] ,
8
+ } ) ;
9
+
10
+ export type Plugin = PluginNoContext <
11
+ GqlContextType ,
12
+ YogaDriverServerContext < 'fastify' >
13
+ > ;
You can’t perform that action at this time.
0 commit comments