diff --git a/packages/graphql-zeus-core/TreeToTS/functions/new/resolvePath.ts b/packages/graphql-zeus-core/TreeToTS/functions/new/resolvePath.ts index 245336ab..69a69a37 100644 --- a/packages/graphql-zeus-core/TreeToTS/functions/new/resolvePath.ts +++ b/packages/graphql-zeus-core/TreeToTS/functions/new/resolvePath.ts @@ -136,7 +136,16 @@ export const InternalArgsBuilt = ({ // 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); + + if (scalarKey === 'UUID' && Array.isArray(a)) { + return `[${a.map((uuid) => scalars?.[scalarKey]?.encode?.(uuid) || JSON.stringify(uuid)).join(', ')}]`; + } else { + // Handling for other scalars + return (scalars?.[scalarKey]?.encode?.(a) as string) || JSON.stringify(a); + } + } + if (a === undefined) { + return 'ids: null'; } if (Array.isArray(a)) { return `[${a.map((arr) => arb(arr, p, false)).join(', ')}]`; diff --git a/packages/graphql-zeus-core/__tests__/uuid-test.spec.ts b/packages/graphql-zeus-core/__tests__/uuid-test.spec.ts new file mode 100644 index 00000000..565bd534 --- /dev/null +++ b/packages/graphql-zeus-core/__tests__/uuid-test.spec.ts @@ -0,0 +1,68 @@ +import { ZeusScalars } from '@/TreeToTS/functions/new/clientFunctions'; +import { AllTypesPropsType, Operations, ReturnTypesType, ZeusArgsType } from '@/TreeToTS/functions/new/models'; +import { InternalArgsBuilt } from '@/TreeToTS/functions/new/resolvePath'; + +// Define your scalars +const scalars = ZeusScalars({ + UUID: { + encode: (e: unknown) => String(`"${e}"`), + decode: (e: unknown) => e as string, + }, +}); + +describe('InternalArgsBuilt function', () => { + let props: AllTypesPropsType; + let returns: ReturnTypesType; + let ops: Operations; + let vars: Array<{ name: string; graphQLType: string }>; + + beforeEach(() => { + props = {}; + returns = {}; + ops = {}; + vars = []; + }); + + it('should correctly encode UUIDs in a mutation input', () => { + const uuidArrayInput = { + ids: ['0170743b-6876-4ec2-839c-23480da37b28', '3ed80968-a077-4e43-9552-21ee8812f615'], + } as ZeusArgsType; + + const arb = InternalArgsBuilt({ props, returns, ops, scalars, vars }); + const result = arb(uuidArrayInput, 'someMutation.ids', true); + + const expectedOutput = `ids: ["0170743b-6876-4ec2-839c-23480da37b28", "3ed80968-a077-4e43-9552-21ee8812f615"]`; + + expect(result).toEqual(expectedOutput); + }); + + it('should encode non-empty UUID arrays with consistent UUIDs', () => { + const uuid1 = '0170743b-6876-4ec2-839c-23480da37b28'; + const uuid2 = '3ed80968-a077-4e43-9552-21ee8812f615'; + + const nonEmptyUUIDArrayInput = { ids: [uuid1, uuid2] } as ZeusArgsType; + const arb = InternalArgsBuilt({ props, returns, ops, scalars, vars }); + const result = arb(nonEmptyUUIDArrayInput, 'someMutation.ids', true); + + const expectedOutput = `ids: ["0170743b-6876-4ec2-839c-23480da37b28", "3ed80968-a077-4e43-9552-21ee8812f615"]`; + + expect(result).toEqual(expectedOutput); + }); + + it('should handle null input gracefully', () => { + const nullInput = { ids: null } as ZeusArgsType; + const arb = InternalArgsBuilt({ props, returns, ops, scalars, vars }); + const result = arb(nullInput, 'someMutation.ids', true); + + const expectedOutput = `ids: null`; + + expect(result).toEqual(expectedOutput); + }); + + it('should handle undefined input gracefully', () => { + const arb = InternalArgsBuilt({ props, returns, ops, scalars, vars }); + const result = arb(undefined, 'someMutation.ids', true); // Pass undefined as input + expect(result).toEqual('ids: null'); // Expect the result to be 'ids: null' + }); + +});