From 8d9b94c2f3f88c696520d94ef6cd5c98df81a92f Mon Sep 17 00:00:00 2001 From: Aaron S <94858815+stocaaro@users.noreply.github.com> Date: Wed, 6 Dec 2023 11:06:31 -0600 Subject: [PATCH] fix: Arrays returned as objects (#12676) --- packages/api-graphql/__tests__/fixtures/modeled/schema.ts | 1 + packages/api-graphql/__tests__/generateClient.test.ts | 2 ++ packages/api-graphql/src/internals/APIClient.ts | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/api-graphql/__tests__/fixtures/modeled/schema.ts b/packages/api-graphql/__tests__/fixtures/modeled/schema.ts index abdd7fffedd..08f8db63cc8 100644 --- a/packages/api-graphql/__tests__/fixtures/modeled/schema.ts +++ b/packages/api-graphql/__tests__/fixtures/modeled/schema.ts @@ -7,6 +7,7 @@ const schema = a.schema({ description: a.string(), notes: a.hasMany('Note'), meta: a.hasOne('TodoMetadata'), + tags: a.string().array(), }) .authorization([a.allow.public('apiKey'), a.allow.owner()]), Note: a diff --git a/packages/api-graphql/__tests__/generateClient.test.ts b/packages/api-graphql/__tests__/generateClient.test.ts index 7f586f62c0a..d445335c94b 100644 --- a/packages/api-graphql/__tests__/generateClient.test.ts +++ b/packages/api-graphql/__tests__/generateClient.test.ts @@ -272,6 +272,7 @@ describe('generateClient', () => { ...serverManagedFields, name: 'some name', description: 'something something', + tags: ['one', 'two', 'three'] }, }, }); @@ -288,6 +289,7 @@ describe('generateClient', () => { owner: 'wirejobviously', name: 'some name', description: 'something something', + tags: ['one', 'two', 'three'] }) ); }); diff --git a/packages/api-graphql/src/internals/APIClient.ts b/packages/api-graphql/src/internals/APIClient.ts index 100c8230f12..993ed19ace5 100644 --- a/packages/api-graphql/src/internals/APIClient.ts +++ b/packages/api-graphql/src/internals/APIClient.ts @@ -48,7 +48,7 @@ export const flattenItems = (obj: Record): Record => { const res: Record = {}; Object.entries(obj).forEach(([prop, value]) => { - if (typeof value === 'object' && value !== null) { + if (typeof value === 'object' && !Array.isArray(value) && value !== null) { if (value.items !== undefined) { res[prop] = value.items.map((item: Record) => flattenItems(item)