1
1
import { Injectable } from '@nestjs/common' ;
2
2
import { loadPackage } from '@nestjs/common/utils/load-package.util' ;
3
3
import { ModulesContainer } from '@nestjs/core' ;
4
- import { extend , GraphQLFederationFactory } from '@nestjs/graphql' ;
4
+ import {
5
+ extend ,
6
+ GqlSubscriptionService ,
7
+ GraphQLFederationFactory ,
8
+ SubscriptionConfig ,
9
+ } from '@nestjs/graphql' ;
5
10
import { GraphQLSchema } from 'graphql' ;
6
11
import { ApolloDriverConfig } from '../interfaces' ;
7
12
import { PluginsExplorerService } from '../services/plugins-explorer.service' ;
@@ -12,6 +17,7 @@ import { ApolloBaseDriver } from './apollo-base.driver';
12
17
*/
13
18
@Injectable ( )
14
19
export class ApolloFederationDriver extends ApolloBaseDriver {
20
+ private _subscriptionService ?: GqlSubscriptionService ;
15
21
private readonly pluginsExplorerService : PluginsExplorerService ;
16
22
17
23
constructor (
@@ -43,9 +49,16 @@ export class ApolloFederationDriver extends ApolloBaseDriver {
43
49
await super . start ( options ) ;
44
50
45
51
if ( options . installSubscriptionHandlers || options . subscriptions ) {
46
- // TL;DR <https://github.com/apollographql/apollo-server/issues/2776>
47
- throw new Error (
48
- 'No support for subscriptions yet when using Apollo Federation' ,
52
+ const subscriptionsOptions : SubscriptionConfig =
53
+ options . subscriptions || { 'subscriptions-transport-ws' : { } } ;
54
+ this . _subscriptionService = new GqlSubscriptionService (
55
+ {
56
+ schema : options . schema ,
57
+ path : options . path ,
58
+ context : options . context ,
59
+ ...subscriptionsOptions ,
60
+ } ,
61
+ this . httpAdapterHost . httpAdapter ?. getHttpServer ( ) ,
49
62
) ;
50
63
}
51
64
}
0 commit comments