Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass queue names as options param #82

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading