From 56a82da1ad7736350812d4f1910e09eb012be727 Mon Sep 17 00:00:00 2001 From: Gautier Date: Tue, 28 Jun 2022 09:30:33 +0200 Subject: [PATCH] fix(#314): added explicit runtime error --- src/TreeToTS/functions/generated.ts | 2 ++ src/TreeToTS/functions/new/resolvePath.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/src/TreeToTS/functions/generated.ts b/src/TreeToTS/functions/generated.ts index 723245b0..cb331a41 100644 --- a/src/TreeToTS/functions/generated.ts +++ b/src/TreeToTS/functions/generated.ts @@ -558,6 +558,7 @@ export const ResolveFromPath = (props: AllTypesPropsType, returns: ReturnTypesTy const oKey = ops[mappedParts[0].v]; const returnP1 = oKey ? returns[oKey] : returns[mappedParts[0].v]; if (typeof returnP1 === 'object') { + if (!mappedParts[1]) throw new Error(\`\${mappedParts[0].v} does not take arguments\`); const returnP2 = returnP1[mappedParts[1].v]; if (returnP2) { return rpp( @@ -601,6 +602,7 @@ export const InternalArgsBuilt = ({ const arb = (a: ZeusArgsType, p = '', root = true): string => { const checkType = ResolveFromPath(props, returns, ops)(p); if (checkType.startsWith('scalar.')) { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const [_, ...splittedScalar] = checkType.split('.'); const scalarKey = splittedScalar.join('.'); return (scalars?.[scalarKey]?.encode?.(a) as string) || JSON.stringify(a); diff --git a/src/TreeToTS/functions/new/resolvePath.ts b/src/TreeToTS/functions/new/resolvePath.ts index 472138dc..193f1f4f 100644 --- a/src/TreeToTS/functions/new/resolvePath.ts +++ b/src/TreeToTS/functions/new/resolvePath.ts @@ -69,6 +69,7 @@ export const ResolveFromPath = (props: AllTypesPropsType, returns: ReturnTypesTy const oKey = ops[mappedParts[0].v]; const returnP1 = oKey ? returns[oKey] : returns[mappedParts[0].v]; if (typeof returnP1 === 'object') { + if (!mappedParts[1]) throw new Error(`${mappedParts[0].v} does not take arguments`); const returnP2 = returnP1[mappedParts[1].v]; if (returnP2) { return rpp(