@orion-js/graphql 3.3.21 → 3.3.24

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/lib/pubsub.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { PubSub } from 'graphql-subscriptions';
2
- export declare const setPubsub: (newPubsub: PubSub) => void;
3
- export declare const getPubsub: () => PubSub;
1
+ import { PubSubEngine } from 'graphql-subscriptions';
2
+ export declare const setPubsub: (newPubsub: PubSubEngine) => void;
3
+ export declare const getPubsub: () => PubSubEngine;
@@ -1,2 +1,3 @@
1
1
  export * from './global';
2
2
  export * from './model';
3
+ export * from './subscription';
@@ -12,3 +12,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./global"), exports);
14
14
  __exportStar(require("./model"), exports);
15
+ __exportStar(require("./subscription"), exports);
@@ -0,0 +1,6 @@
1
+ import { OrionSubscription, OrionSubscriptionOptions } from '../types/subscription';
2
+ export declare function Subscriptions(): ClassDecorator;
3
+ export declare function Subscription<T = any, ReturnType = any>(options: OrionSubscriptionOptions): (object: any, propertyName: string, index?: number) => void;
4
+ export declare function getServiceSubscriptions(target: any): {
5
+ [key: string]: OrionSubscription;
6
+ };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getServiceSubscriptions = exports.Subscription = exports.Subscriptions = void 0;
4
+ const services_1 = require("@orion-js/services");
5
+ const helpers_1 = require("@orion-js/helpers");
6
+ const __1 = require("..");
7
+ function Subscriptions() {
8
+ return function (target) {
9
+ (0, services_1.Service)()(target);
10
+ target.prototype.service = target;
11
+ target.prototype.serviceType = 'subscriptions';
12
+ };
13
+ }
14
+ exports.Subscriptions = Subscriptions;
15
+ function Subscription(options) {
16
+ return function (object, propertyName, index) {
17
+ const sub = (0, __1.subscription)(options);
18
+ object.subscriptions = object.subscriptions || {};
19
+ object.subscriptions[propertyName] = sub;
20
+ services_1.Container.registerHandler({
21
+ object,
22
+ propertyName,
23
+ index,
24
+ value: containerInstance => {
25
+ if (!object.serviceType || object.serviceType !== 'subscriptions') {
26
+ throw new Error('You must pass a class decorated with @Subscriptions if you want to use @Subscription');
27
+ }
28
+ return sub;
29
+ }
30
+ });
31
+ };
32
+ }
33
+ exports.Subscription = Subscription;
34
+ function getServiceSubscriptions(target) {
35
+ if (!target.prototype) {
36
+ throw new helpers_1.UserError('You must pass a class to getSubscriptions');
37
+ }
38
+ return target.prototype.subscriptions || {};
39
+ }
40
+ exports.getServiceSubscriptions = getServiceSubscriptions;
@@ -0,0 +1 @@
1
+ import 'reflect-metadata';
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ require("reflect-metadata");
13
+ const index_1 = require("./index");
14
+ const services_1 = require("@orion-js/services");
15
+ const typed_model_1 = require("@orion-js/typed-model");
16
+ describe('Subscriptions classes', () => {
17
+ it('should get the subscriptions using services', async () => {
18
+ let Params = class Params {
19
+ };
20
+ __decorate([
21
+ (0, typed_model_1.Prop)(),
22
+ __metadata("design:type", String)
23
+ ], Params.prototype, "name", void 0);
24
+ Params = __decorate([
25
+ (0, typed_model_1.TypedSchema)()
26
+ ], Params);
27
+ let User = class User {
28
+ };
29
+ __decorate([
30
+ (0, typed_model_1.Prop)(),
31
+ __metadata("design:type", String)
32
+ ], User.prototype, "name", void 0);
33
+ User = __decorate([
34
+ (0, typed_model_1.TypedSchema)()
35
+ ], User);
36
+ let ExampleSubscriptionsService = class ExampleSubscriptionsService {
37
+ };
38
+ __decorate([
39
+ (0, index_1.Subscription)({
40
+ params: Params,
41
+ returns: User
42
+ }),
43
+ __metadata("design:type", Object)
44
+ ], ExampleSubscriptionsService.prototype, "onUserCreated", void 0);
45
+ ExampleSubscriptionsService = __decorate([
46
+ (0, index_1.Subscriptions)()
47
+ ], ExampleSubscriptionsService);
48
+ const subscriptions = (0, index_1.getServiceSubscriptions)(ExampleSubscriptionsService);
49
+ expect(subscriptions.onUserCreated).toBeDefined();
50
+ const instance = (0, services_1.getInstance)(ExampleSubscriptionsService);
51
+ expect(instance.onUserCreated.publish).toBeDefined();
52
+ // await instance.onUserCreated.publish({name: 'test'}, {name: 'test'})
53
+ });
54
+ });
@@ -1,3 +1,4 @@
1
+ import { StartGraphQLOptions } from './types/startGraphQL';
1
2
  export default function ({ schema }: {
2
3
  schema: any;
3
- }, options: any): void;
4
+ }, options: StartGraphQLOptions): void;
@@ -7,8 +7,9 @@ const pubsub_1 = require("./pubsub");
7
7
  const http_1 = require("@orion-js/http");
8
8
  const websockerViewer_1 = require("./websockerViewer");
9
9
  function default_1({ schema }, options) {
10
- (0, pubsub_1.setPubsub)(options.pubsub || new graphql_subscriptions_1.PubSub());
11
- const server = options.server || (0, http_1.getApp)();
10
+ const pubsub = options.pubsub || new graphql_subscriptions_1.PubSub();
11
+ (0, pubsub_1.setPubsub)(pubsub);
12
+ const server = options.app || (0, http_1.getApp)();
12
13
  if (!server) {
13
14
  throw new Error('Error starting GraphQL WebSocket. You must start http server before starting GraphQL WebSocket');
14
15
  }
@@ -114,8 +114,8 @@ const gqClient = async () => {
114
114
  // We pass customServer instead of typical configuration of a default WebSocket server
115
115
  const { apolloOptions, subscriptions } = await getStartServerOptions();
116
116
  const uri = `ws://localhost:${RANDOM_WS_PORT}`;
117
- const server = new mock_socket_with_protocol_1.Server(uri);
118
- (0, startWebsocket_1.default)({ schema: apolloOptions.schema }, { server });
117
+ const app = new mock_socket_with_protocol_1.Server(uri);
118
+ (0, startWebsocket_1.default)({ schema: apolloOptions.schema }, { app, resolvers: {} });
119
119
  const getConnectionParams = () => {
120
120
  return { jwt: 'hi' };
121
121
  };
@@ -1,3 +1,3 @@
1
- import { CreateSubscriptionFunction } from '../types/subscription';
2
- declare const createSubscription: CreateSubscriptionFunction;
1
+ import { CreateOrionSubscriptionFunction } from '../types/subscription';
2
+ declare const createSubscription: CreateOrionSubscriptionFunction;
3
3
  export default createSubscription;
@@ -1,7 +1,8 @@
1
1
  import { GlobalResolversMap, ModelResolversMap } from '@orion-js/models';
2
2
  import { express } from '@orion-js/http';
3
- import { SubscriptionMap } from './subscription';
3
+ import { OrionSubscriptionsMap } from './subscription';
4
4
  import { GraphQLOptions } from 'apollo-server-core';
5
+ import { PubSubEngine } from 'graphql-subscriptions';
5
6
  export declare type ExecuteGraphQLCache = (req: express.Request, res: express.Response, viewer: object, executeQuery: () => Promise<string>) => Promise<string>;
6
7
  export interface ModelsResolversMap {
7
8
  [key: string]: ModelResolversMap;
@@ -19,7 +20,7 @@ export interface StartGraphQLOptions extends Omit<GraphQLOptions, SchemaOmits> {
19
20
  /**
20
21
  * A Map with all global subscriptions
21
22
  */
22
- subscriptions?: SubscriptionMap;
23
+ subscriptions?: OrionSubscriptionsMap;
23
24
  /**
24
25
  * A function that executes the http level cache of graphql queries
25
26
  */
@@ -32,5 +33,10 @@ export interface StartGraphQLOptions extends Omit<GraphQLOptions, SchemaOmits> {
32
33
  * Pass another express app
33
34
  */
34
35
  app?: express.Application;
36
+ /**
37
+ * The pubsub provider to use. Default to the single server pubsub.
38
+ * If you are using multiple servers you must pass a pubsub provider like RedisPubSub
39
+ */
40
+ pubsub?: PubSubEngine;
35
41
  }
36
42
  export {};
@@ -1,14 +1,14 @@
1
1
  import { ResolverOptions } from '@orion-js/resolvers';
2
- export interface Subscription<T = any, ReturnType = any> {
2
+ export interface OrionSubscription<TParams = any, ReturnType = any> {
3
3
  key: string;
4
4
  params: object;
5
5
  subscribe: (callParams: object, viewer: object) => {};
6
6
  returns: ReturnType;
7
- publish: (params: T, data: ReturnType) => Promise<void>;
7
+ publish: (params: TParams, data: ReturnType) => Promise<void>;
8
8
  }
9
- export declare type CreateSubscriptionFunction = <T = any, ReturnType = any>(options: SubscriptionOptions) => Subscription<T, ReturnType>;
10
- export interface SubscriptionMap {
11
- [key: string]: Subscription;
9
+ export declare type CreateOrionSubscriptionFunction = <T = any, ReturnType = any>(options: OrionSubscriptionOptions) => OrionSubscription<T, ReturnType>;
10
+ export interface OrionSubscriptionsMap {
11
+ [key: string]: OrionSubscription;
12
12
  }
13
- export interface SubscriptionOptions extends Omit<ResolverOptions, 'resolve'> {
13
+ export interface OrionSubscriptionOptions extends Omit<ResolverOptions, 'resolve'> {
14
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/graphql",
3
- "version": "3.3.21",
3
+ "version": "3.3.24",
4
4
  "main": "lib/index.js",
5
5
  "author": "nicolaslopezj",
6
6
  "license": "MIT",
@@ -45,5 +45,5 @@
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
- "gitHead": "c24dc7ba82493710c5d2a1a593ff4ed9eddd3090"
48
+ "gitHead": "feaf1c65091873a8a59d674a681c37bb9607b35b"
49
49
  }