|
1 | | -import { schemaComposer, SchemaComposer } from 'graphql-compose'; |
| 1 | +import { |
| 2 | + schemaComposer, |
| 3 | + SchemaComposer, |
| 4 | + ObjectTypeComposer, |
| 5 | + ObjectTypeComposerFieldConfigAsObjectDefinition, |
| 6 | +} from 'graphql-compose'; |
2 | 7 | import { Options } from './definitions'; |
3 | 8 | import { getQueueTC, getJobTC } from './types'; |
4 | 9 | import { |
@@ -29,17 +34,27 @@ import { |
29 | 34 | createJobMoveToDelayedFC, |
30 | 35 | createQueuePepUpFC, |
31 | 36 | } from './mutation'; |
32 | | -import { createJobAddSubFC } from './subscriptions'; |
| 37 | +import { createOnJobWaitingFC } from './subscriptions'; |
33 | 38 | import { wrapMutationFC, wrapQueueArgs, wrapQueueSubsArgs, composeFC } from './helpers'; |
34 | 39 |
|
35 | | -export function composeBull(opts: Options & { schemaComposer?: SchemaComposer<any> }) { |
| 40 | +interface ComposeBullResult { |
| 41 | + QueueTC: ObjectTypeComposer; |
| 42 | + JobTC: ObjectTypeComposer; |
| 43 | + queryFields: Record<string, ObjectTypeComposerFieldConfigAsObjectDefinition<any, any>>; |
| 44 | + mutationFields: Record<string, ObjectTypeComposerFieldConfigAsObjectDefinition<any, any>>; |
| 45 | + subscriptionFields?: Record<string, ObjectTypeComposerFieldConfigAsObjectDefinition<any, any>>; |
| 46 | +} |
| 47 | + |
| 48 | +export function composeBull( |
| 49 | + opts: Options & { schemaComposer?: SchemaComposer<any> } |
| 50 | +): ComposeBullResult { |
36 | 51 | const sc = opts?.schemaComposer || schemaComposer; |
37 | 52 |
|
38 | 53 | const wrapQuery = composeFC(sc, opts)(wrapQueueArgs); |
39 | 54 | const wrapMutation = composeFC(sc, opts)(wrapMutationFC, wrapQueueArgs); |
40 | 55 | const wrapSubscription = composeFC(sc, opts)(wrapQueueSubsArgs); |
41 | 56 |
|
42 | | - return { |
| 57 | + const data = { |
43 | 58 | QueueTC: getQueueTC(sc, opts), |
44 | 59 | JobTC: getJobTC(sc, opts), |
45 | 60 | queryFields: { |
@@ -70,8 +85,13 @@ export function composeBull(opts: Options & { schemaComposer?: SchemaComposer<an |
70 | 85 | jobMoveToDelayed: wrapMutation(createJobMoveToDelayedFC), |
71 | 86 | queuePepUp: wrapMutation(createQueuePepUpFC), |
72 | 87 | }, |
73 | | - subscriptionFields: { |
74 | | - jobAddSub: wrapSubscription(createJobAddSubFC), |
75 | | - }, |
76 | | - }; |
| 88 | + } as ComposeBullResult; |
| 89 | + |
| 90 | + if (opts?.redisEvents) { |
| 91 | + data.subscriptionFields = { |
| 92 | + onJobWaiting: wrapSubscription(createOnJobWaitingFC), |
| 93 | + }; |
| 94 | + } |
| 95 | + |
| 96 | + return data; |
77 | 97 | } |
0 commit comments