@rxdi/graphql-pubsub 0.7.180 → 0.7.182

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.
@@ -1,2 +1,50 @@
1
- import { ResolverFn, FilterFn } from 'graphql-subscriptions';
2
- export declare function Subscribe<T>(asyncIteratorFunction: ResolverFn | AsyncIterator<T>, filterFn?: FilterFn): Function;
1
+ import { ResolverFn } from 'graphql-subscriptions';
2
+ /**
3
+ * @Subscribe annotation
4
+ * @param asyncIteratorFunction accepts ResolverFn or AsyncIterator<T>
5
+ *
6
+ * Can be imported from "graphql-subscriptions" package as function "withFilter"
7
+ *
8
+ ```typescript
9
+
10
+ import { PubSubService } from '@rxdi/graphql-pubsub';
11
+ import { withFilter } from 'graphql-subscriptions'
12
+
13
+ @Controller<GraphQLControllerOptions>()
14
+ export class ChatController {
15
+ constructor(
16
+ private pubsub: PubSubService,
17
+ ) {}
18
+
19
+ @Subscribe(
20
+ withFilter(
21
+ (self: ChatController) => self.pubsub.asyncIterator('MySubscriptionChannel'),
22
+ async (
23
+ message: IChatMessage,
24
+ {id}: {id: string},
25
+ context: GraphqlContext,
26
+ ) => {
27
+ // If you want to notify subscribed clients return true
28
+ // usefull when you want to check if this user has rights to access this pubsub queue
29
+ // Check something with payload arguments provided as id
30
+ // This id can be defined in @Subscription({ id: { type:... }})
31
+ return true
32
+ }
33
+ )
34
+ )
35
+ @Subscription({
36
+ id: {
37
+ type: new GraphQLNonNull(GraphQLString)
38
+ }
39
+ })
40
+ async mySubscription(payload: any) {
41
+ return message;
42
+ }
43
+
44
+ publisher() {
45
+ this.pubsub.publish('MySubscriptionChannel', { id: 'my-id' });
46
+ }
47
+ }
48
+ ```
49
+ */
50
+ export declare function Subscribe<T>(asyncIteratorFunction: ResolverFn | AsyncIterator<T>): Function;
@@ -1,7 +1,55 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Subscribe = void 0;
4
- function Subscribe(asyncIteratorFunction, filterFn) {
4
+ /**
5
+ * @Subscribe annotation
6
+ * @param asyncIteratorFunction accepts ResolverFn or AsyncIterator<T>
7
+ *
8
+ * Can be imported from "graphql-subscriptions" package as function "withFilter"
9
+ *
10
+ ```typescript
11
+
12
+ import { PubSubService } from '@rxdi/graphql-pubsub';
13
+ import { withFilter } from 'graphql-subscriptions'
14
+
15
+ @Controller<GraphQLControllerOptions>()
16
+ export class ChatController {
17
+ constructor(
18
+ private pubsub: PubSubService,
19
+ ) {}
20
+
21
+ @Subscribe(
22
+ withFilter(
23
+ (self: ChatController) => self.pubsub.asyncIterator('MySubscriptionChannel'),
24
+ async (
25
+ message: IChatMessage,
26
+ {id}: {id: string},
27
+ context: GraphqlContext,
28
+ ) => {
29
+ // If you want to notify subscribed clients return true
30
+ // usefull when you want to check if this user has rights to access this pubsub queue
31
+ // Check something with payload arguments provided as id
32
+ // This id can be defined in @Subscription({ id: { type:... }})
33
+ return true
34
+ }
35
+ )
36
+ )
37
+ @Subscription({
38
+ id: {
39
+ type: new GraphQLNonNull(GraphQLString)
40
+ }
41
+ })
42
+ async mySubscription(payload: any) {
43
+ return message;
44
+ }
45
+
46
+ publisher() {
47
+ this.pubsub.publish('MySubscriptionChannel', { id: 'my-id' });
48
+ }
49
+ }
50
+ ```
51
+ */
52
+ function Subscribe(asyncIteratorFunction) {
5
53
  const subscribe = { subscribe: asyncIteratorFunction };
6
54
  return (t, propKey, desc) => {
7
55
  const descriptor = desc;
@@ -1 +1,19 @@
1
- export declare function Subscription(options?: any): (t: any, propKey: string, descriptor: TypedPropertyDescriptor<any>) => TypedPropertyDescriptor<any>;
1
+ import { GraphQLInputFieldConfigMap } from 'graphql';
2
+ /**
3
+ * @Subscription annotation is creating GraphQLInputObjectType dynamically
4
+ * @param fields parameter is type GraphQLInputFieldConfigMap
5
+ * @param meta parameter has "description" field which is then added to the new GraphQLInputObjectType
6
+ *
7
+ * "input" param is actually "fields" param inside the dynamically generated GraphQLInputObjectType
8
+ *
9
+ * ```typescript
10
+ * new GraphQLInputObjectType({
11
+ * name: 'Taken from the descriptor name automatically',
12
+ * description: 'Taken from "meta.description" field'
13
+ * fields: input,
14
+ * })
15
+ * ```
16
+ */
17
+ export declare function Subscription(fields?: GraphQLInputFieldConfigMap, meta?: {
18
+ description?: string;
19
+ }): (t: any, propKey: string, descriptor: TypedPropertyDescriptor<any>) => TypedPropertyDescriptor<any>;
@@ -1,7 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Subscription = void 0;
4
- function Subscription(options) {
4
+ /**
5
+ * @Subscription annotation is creating GraphQLInputObjectType dynamically
6
+ * @param fields parameter is type GraphQLInputFieldConfigMap
7
+ * @param meta parameter has "description" field which is then added to the new GraphQLInputObjectType
8
+ *
9
+ * "input" param is actually "fields" param inside the dynamically generated GraphQLInputObjectType
10
+ *
11
+ * ```typescript
12
+ * new GraphQLInputObjectType({
13
+ * name: 'Taken from the descriptor name automatically',
14
+ * description: 'Taken from "meta.description" field'
15
+ * fields: input,
16
+ * })
17
+ * ```
18
+ */
19
+ function Subscription(fields, meta) {
5
20
  return (t, propKey, descriptor) => {
6
21
  const originalMethod = descriptor.value;
7
22
  const target = t;
@@ -9,9 +24,10 @@ function Subscription(options) {
9
24
  descriptor.value = function (...args) {
10
25
  const returnValue = Object.create({});
11
26
  returnValue.resolve = originalMethod;
12
- returnValue.args = options ? options : null;
27
+ returnValue.args = fields ? fields : null;
13
28
  returnValue.method_type = 'subscription';
14
29
  returnValue.method_name = propertyKey;
30
+ returnValue.description = meta ? meta.description : null;
15
31
  returnValue.target = target;
16
32
  return returnValue;
17
33
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdi/graphql-pubsub",
3
- "version": "0.7.180",
3
+ "version": "0.7.182",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/rxdi/graphql-pubsub"
@@ -30,16 +30,16 @@
30
30
  },
31
31
  "homepage": "https://github.com/rxdi/graphql-pubsub#readme",
32
32
  "dependencies": {
33
- "@rxdi/graphql-rabbitmq-subscriptions": "^0.7.179",
33
+ "@rxdi/graphql-rabbitmq-subscriptions": "^0.7.181",
34
34
  "@apollo/client": "^3.7.3",
35
35
  "graphql-request": "^1.8.2",
36
36
  "subscriptions-transport-ws": "^0.9.19",
37
37
  "ws": "6.2.1"
38
38
  },
39
39
  "devDependencies": {
40
- "@rxdi/core": "^0.7.179",
41
- "@rxdi/graphql": "^0.7.179",
42
- "@rxdi/hapi": "^0.7.179",
40
+ "@rxdi/core": "^0.7.181",
41
+ "@rxdi/graphql": "^0.7.181",
42
+ "@rxdi/hapi": "^0.7.181",
43
43
  "@types/graphql": "^14.5.0",
44
44
  "@types/hapi": "^18.0.4",
45
45
  "@types/jest": "^24.0.22",