@graphql-yoga/nestjs-federation 2.0.4 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @graphql-yoga/nestjs-federation
2
2
 
3
+ ## 2.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2966](https://github.com/dotansimha/graphql-yoga/pull/2966)
8
+ [`5740159d`](https://github.com/dotansimha/graphql-yoga/commit/5740159d6f599affc04cb58ea40f9fcbe2efd32f)
9
+ Thanks [@vasily-polonsky](https://github.com/vasily-polonsky)! - support subscriptions for nestjs
10
+ federation
11
+
3
12
  ## 2.0.4
4
13
 
5
14
  ### Patch Changes
package/dist/cjs/index.js CHANGED
@@ -29,11 +29,23 @@ let YogaFederationDriver = exports.YogaFederationDriver = class YogaFederationDr
29
29
  ...options,
30
30
  plugins: [...(options?.plugins || []), (0, plugin_apollo_inline_trace_1.useApolloInlineTrace)()],
31
31
  });
32
- if (options.subscriptions) {
33
- // See more: https://github.com/apollographql/apollo-server/issues/2776
34
- throw new Error('No support for subscriptions when using Apollo Federation');
32
+ if (options.subscriptions && options.schema) {
33
+ const config = options.subscriptions === true
34
+ ? {
35
+ 'graphql-ws': true,
36
+ }
37
+ : options.subscriptions;
38
+ this.subscriptionService = new graphql_2.GqlSubscriptionService({
39
+ schema: options.schema,
40
+ path: options.path,
41
+ context: options.context,
42
+ ...config,
43
+ }, this.httpAdapterHost.httpAdapter?.getHttpServer());
35
44
  }
36
45
  }
46
+ async stop() {
47
+ await this.subscriptionService?.stop();
48
+ }
37
49
  };
38
50
  exports.YogaFederationDriver = YogaFederationDriver = tslib_1.__decorate([
39
51
  (0, common_1.Injectable)(),
package/dist/esm/index.js CHANGED
@@ -6,7 +6,7 @@ import { useApolloFederation } from '@envelop/apollo-federation';
6
6
  import { AbstractYogaDriver, } from '@graphql-yoga/nestjs';
7
7
  import { useApolloInlineTrace } from '@graphql-yoga/plugin-apollo-inline-trace';
8
8
  import { Injectable } from '@nestjs/common';
9
- import { GraphQLFederationFactory } from '@nestjs/graphql';
9
+ import { GqlSubscriptionService, GraphQLFederationFactory, } from '@nestjs/graphql';
10
10
  export let YogaFederationDriver = class YogaFederationDriver extends AbstractYogaDriver {
11
11
  constructor(graphqlFederationFactory) {
12
12
  super();
@@ -26,11 +26,23 @@ export let YogaFederationDriver = class YogaFederationDriver extends AbstractYog
26
26
  ...options,
27
27
  plugins: [...(options?.plugins || []), useApolloInlineTrace()],
28
28
  });
29
- if (options.subscriptions) {
30
- // See more: https://github.com/apollographql/apollo-server/issues/2776
31
- throw new Error('No support for subscriptions when using Apollo Federation');
29
+ if (options.subscriptions && options.schema) {
30
+ const config = options.subscriptions === true
31
+ ? {
32
+ 'graphql-ws': true,
33
+ }
34
+ : options.subscriptions;
35
+ this.subscriptionService = new GqlSubscriptionService({
36
+ schema: options.schema,
37
+ path: options.path,
38
+ context: options.context,
39
+ ...config,
40
+ }, this.httpAdapterHost.httpAdapter?.getHttpServer());
32
41
  }
33
42
  }
43
+ async stop() {
44
+ await this.subscriptionService?.stop();
45
+ }
34
46
  };
35
47
  YogaFederationDriver = __decorate([
36
48
  Injectable(),
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-yoga/nestjs-federation",
3
- "version": "2.0.4",
3
+ "version": "2.1.0",
4
4
  "description": "GraphQL Yoga driver with Apollo Federation for NestJS GraphQL.",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -6,9 +6,11 @@ import { GraphQLFederationFactory } from '@nestjs/graphql';
6
6
  export type YogaFederationDriverConfig<Platform extends YogaDriverPlatform = 'express'> = YogaDriverConfig<Platform>;
7
7
  export declare class YogaFederationDriver<Platform extends YogaDriverPlatform = 'express'> extends AbstractYogaDriver<Platform> {
8
8
  private readonly graphqlFederationFactory;
9
+ private subscriptionService?;
9
10
  constructor(graphqlFederationFactory: GraphQLFederationFactory);
10
11
  generateSchema(options: YogaFederationDriverConfig<Platform>): Promise<GraphQLSchema>;
11
12
  start(options: YogaFederationDriverConfig<Platform>): Promise<void>;
13
+ stop(): Promise<void>;
12
14
  }
13
15
  export interface YogaGatewayDriverConfig<Platform extends YogaDriverPlatform = 'express'> {
14
16
  driver?: Type<YogaDriver<Platform>>;
@@ -6,9 +6,11 @@ import { GraphQLFederationFactory } from '@nestjs/graphql';
6
6
  export type YogaFederationDriverConfig<Platform extends YogaDriverPlatform = 'express'> = YogaDriverConfig<Platform>;
7
7
  export declare class YogaFederationDriver<Platform extends YogaDriverPlatform = 'express'> extends AbstractYogaDriver<Platform> {
8
8
  private readonly graphqlFederationFactory;
9
+ private subscriptionService?;
9
10
  constructor(graphqlFederationFactory: GraphQLFederationFactory);
10
11
  generateSchema(options: YogaFederationDriverConfig<Platform>): Promise<GraphQLSchema>;
11
12
  start(options: YogaFederationDriverConfig<Platform>): Promise<void>;
13
+ stop(): Promise<void>;
12
14
  }
13
15
  export interface YogaGatewayDriverConfig<Platform extends YogaDriverPlatform = 'express'> {
14
16
  driver?: Type<YogaDriver<Platform>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-yoga/nestjs-federation",
3
- "version": "2.0.4",
3
+ "version": "2.1.0",
4
4
  "type": "module",
5
5
  "description": "GraphQL Yoga driver with Apollo Federation for NestJS GraphQL.",
6
6
  "repository": {
package/src/index.ts CHANGED
@@ -10,7 +10,11 @@ import {
10
10
  } from '@graphql-yoga/nestjs';
11
11
  import { useApolloInlineTrace } from '@graphql-yoga/plugin-apollo-inline-trace';
12
12
  import { Injectable, Type } from '@nestjs/common';
13
- import { GraphQLFederationFactory } from '@nestjs/graphql';
13
+ import {
14
+ GqlSubscriptionService,
15
+ GraphQLFederationFactory,
16
+ SubscriptionConfig,
17
+ } from '@nestjs/graphql';
14
18
 
15
19
  export type YogaFederationDriverConfig<Platform extends YogaDriverPlatform = 'express'> =
16
20
  YogaDriverConfig<Platform>;
@@ -19,6 +23,8 @@ export type YogaFederationDriverConfig<Platform extends YogaDriverPlatform = 'ex
19
23
  export class YogaFederationDriver<
20
24
  Platform extends YogaDriverPlatform = 'express',
21
25
  > extends AbstractYogaDriver<Platform> {
26
+ private subscriptionService?: GqlSubscriptionService;
27
+
22
28
  constructor(private readonly graphqlFederationFactory: GraphQLFederationFactory) {
23
29
  super();
24
30
  }
@@ -40,11 +46,29 @@ export class YogaFederationDriver<
40
46
  plugins: [...(options?.plugins || []), useApolloInlineTrace()],
41
47
  });
42
48
 
43
- if (options.subscriptions) {
44
- // See more: https://github.com/apollographql/apollo-server/issues/2776
45
- throw new Error('No support for subscriptions when using Apollo Federation');
49
+ if (options.subscriptions && options.schema) {
50
+ const config: SubscriptionConfig =
51
+ options.subscriptions === true
52
+ ? {
53
+ 'graphql-ws': true,
54
+ }
55
+ : options.subscriptions;
56
+
57
+ this.subscriptionService = new GqlSubscriptionService(
58
+ {
59
+ schema: options.schema,
60
+ path: options.path,
61
+ context: options.context,
62
+ ...config,
63
+ },
64
+ this.httpAdapterHost.httpAdapter?.getHttpServer(),
65
+ );
46
66
  }
47
67
  }
68
+
69
+ public async stop(): Promise<void> {
70
+ await this.subscriptionService?.stop();
71
+ }
48
72
  }
49
73
 
50
74
  export interface YogaGatewayDriverConfig<Platform extends YogaDriverPlatform = 'express'> {