From a25c383cfaa3e8741d97acbcf57062aa5b884dd9 Mon Sep 17 00:00:00 2001 From: Yvann Boucher Date: Tue, 4 Feb 2025 08:54:43 +0400 Subject: [PATCH] Improved inputs' reusability --- .../node/type/output/node/field/virtual.ts | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/graphql-platform/src/node/type/output/node/field/virtual.ts b/packages/graphql-platform/src/node/type/output/node/field/virtual.ts index 56470164..93f52ef9 100644 --- a/packages/graphql-platform/src/node/type/output/node/field/virtual.ts +++ b/packages/graphql-platform/src/node/type/output/node/field/virtual.ts @@ -212,22 +212,18 @@ export class VirtualOutputType< ); const argsConfigPath = utils.addPath(this.configPath, 'args'); - utils.assertNillablePlainObject(argsConfig, argsConfigPath); - if (argsConfig) { - const inputs: utils.Input[] = []; - - if (Array.isArray(argsConfig)) { - inputs.push(...argsConfig); - } else { - for (const [name, config] of Object.entries(argsConfig)) { - if (config) { - const configPath = utils.addPath(argsConfigPath, name); - - inputs.push(new utils.Input({ name, ...config }, configPath)); - } - } - } + const inputs: utils.Input[] = Array.isArray(argsConfig) + ? argsConfig + : Object.entries(utils.ensurePlainObject(argsConfig, argsConfigPath)) + .filter(([, config]) => config) + .map( + ([name, config]) => + new utils.Input( + { name, ...config }, + utils.addPath(argsConfigPath, name), + ), + ); return inputs.length ? inputs : undefined; }