Skip to content

Commit ac31c38

Browse files
committed
refactor: use RepeatOptionsInterface instead of union
1 parent 1b7fcdd commit ac31c38

File tree

6 files changed

+58
-68
lines changed

6 files changed

+58
-68
lines changed

example/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// const BULL_REDIS_URI = 'redis://127.0.0.1:6379';
1010
const BULL_REDIS_URI =
11-
'redis://:uut2tiew5waeli1aefup0Toecaikoque5eepahch5AowaiJ2@10.216.129.127:6379';
11+
'redis://:uut2tiew5waeli1aefup0Toecaikoque5eepahch5AowaiJ2@10.216.129.128:6379';
1212

1313
const BULL_HOST_ID = 'maybe_uuid_and_mac';
1414

example/src/queues/fetchMetrics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if (!BULL_REDIS_URI) {
99
export const queueSettings = {
1010
hostId: BULL_HOST_ID,
1111
name: 'fetch_metrics',
12-
prefix: 'bull.fetch-metrics',
12+
prefix: 'bull.demo',
1313
};
1414

1515
const prefix = queueSettings.prefix;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { isObject, SchemaComposer } from 'graphql-compose';
2+
3+
export function createRepeatOptionsTC(schemaComposer: SchemaComposer<any>) {
4+
const RepeatOptionsInterfaceTC = schemaComposer.createInterfaceTC({
5+
name: 'RepeatOptionsInterface',
6+
fields: {
7+
tz: 'String',
8+
endDate: 'Date',
9+
limit: 'Int',
10+
},
11+
});
12+
13+
const RepeatOptionsCronTC = schemaComposer.createObjectTC({
14+
name: 'RepeatOptionsCron',
15+
interfaces: [RepeatOptionsInterfaceTC],
16+
fields: {
17+
tz: 'String',
18+
endDate: 'Date',
19+
limit: 'Int',
20+
cron: 'String',
21+
startDate: 'Date',
22+
},
23+
});
24+
25+
const RepeatOptionsEveryTC = schemaComposer.createObjectTC({
26+
name: 'RepeatOptionsEvery',
27+
interfaces: [RepeatOptionsInterfaceTC],
28+
fields: {
29+
tz: 'String',
30+
endDate: 'Date',
31+
limit: 'Int',
32+
every: 'String',
33+
},
34+
});
35+
36+
RepeatOptionsInterfaceTC.addTypeResolver(RepeatOptionsEveryTC, (value) => {
37+
return isObject(value) && value.hasOwnProperty('every');
38+
});
39+
40+
RepeatOptionsInterfaceTC.addTypeResolver(RepeatOptionsCronTC, (value) => {
41+
return isObject(value) && value.hasOwnProperty('cron');
42+
});
43+
44+
schemaComposer.addSchemaMustHaveType(RepeatOptionsEveryTC);
45+
schemaComposer.addSchemaMustHaveType(RepeatOptionsCronTC);
46+
47+
return RepeatOptionsInterfaceTC;
48+
}

example/src/schema/types/job/RepeatOptionsUnion.ts

Lines changed: 0 additions & 61 deletions
This file was deleted.

example/src/schema/types/job/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createLogsFC } from './logs';
22
import { createStateFC } from './state';
3-
import { createRepeatOptionsTC } from './RepeatOptionsUnion';
3+
import { createRepeatOptionsTC } from './RepeatOptionsInterface';
44
import { SchemaComposer } from 'graphql-compose';
55

66
export { getJobOptionsInputTC } from './OptionsInput';

example/src/schema/types/job/logs.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Job } from 'bullmq';
1+
import { Job, Queue } from 'bullmq';
22
import { SchemaComposer, ObjectTypeComposerFieldConfigDefinition } from 'graphql-compose';
33

44
export function createLogsFC(
@@ -9,14 +9,17 @@ export function createLogsFC(
99
name: 'JobLogs',
1010
fields: {
1111
count: 'Int',
12-
logs: '[String!]',
12+
items: '[String!]',
1313
},
14+
// args: {}, // TODO: start end
1415
}),
1516
resolve: (job: Job) => {
1617
// `queue` is private property of Job instance
1718
// so here we are not guarantee that log will be avaliable in the future
18-
if ((job as any).queue) {
19-
return (job as any).queue.getJobLogs(job.id);
19+
if (job.id && (job as any).queue) {
20+
return ((job as any).queue as Queue)
21+
.getJobLogs(job.id)
22+
.then((r) => ({ count: r.count, items: r.logs }));
2023
}
2124
},
2225
};

0 commit comments

Comments
 (0)