Skip to content

Commit

Permalink
feat: pass queue names as options param
Browse files Browse the repository at this point in the history
relates: #81
  • Loading branch information
Boris Dorofeev authored and nodkz committed Aug 24, 2023
1 parent 432ad5a commit de890b9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type Options = {
jobDataTC?: string | ObjectTypeComposer<any, any>;
queue?: {
name?: string;
names?: string[];
prefix?: string;
};
redis?: RedisOptions | Redis;
Expand Down
6 changes: 5 additions & 1 deletion src/helpers/wrapQueueArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ export function wrapQueueArgs(
if (opts?.queue?.name && fieldConfig.args?.queueName) {
delete fieldConfig.args.queueName;
}
if (opts?.queue?.names && fieldConfig.args?.queueNames) {
delete fieldConfig.args.queueNames;
}
if (opts?.queue?.prefix && fieldConfig.args?.prefix) {
delete fieldConfig.args.prefix;
}

// pass config props to sub resolve issue
if (opts?.queue?.name || opts?.queue?.prefix) {
if (opts?.queue?.name || opts?.queue?.names || opts?.queue?.prefix) {
const predifinedArgs = {} as Record<string, any>;
if (opts?.queue?.name) predifinedArgs.queueName = opts.queue?.name;
if (opts?.queue?.names) predifinedArgs.queueNames = opts.queue?.names;
if (opts?.queue?.prefix) predifinedArgs.prefix = opts.queue?.prefix;

const subResolve = fieldConfig.resolve || (() => ({}));
Expand Down
8 changes: 4 additions & 4 deletions src/query/queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export function createQueuesFC(
type: 'String',
defaultValue: 'bull',
},
names: {
queueNames: {
type: '[String!]',
},
},
resolve: async (_, { prefix, names }) => {
resolve: async (_, { prefix, queueNames }) => {
//Если передали имена, значит они согласованы с префиксом (bull.[имя проекта]).
const titles = names
? names.map((name: string) => ({ prefix, queueName: name }))
const titles = queueNames
? queueNames.map((name: string) => ({ prefix, queueName: name }))
: await scanQueueTitles(prefix, opts);
return getQueues(titles, opts);
},
Expand Down

0 comments on commit de890b9

Please sign in to comment.