From 5f2cd7b6e26760f1093f89243f36c5ffcd375c62 Mon Sep 17 00:00:00 2001 From: Jochen Rau Date: Sat, 7 May 2022 13:50:55 -0400 Subject: [PATCH] Return an array if the object is a list --- src/lib/common.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib/common.js b/src/lib/common.js index a84e4a79..2e758dfc 100644 --- a/src/lib/common.js +++ b/src/lib/common.js @@ -290,6 +290,13 @@ function introspectionArgToVariable({ ) } +function isList(type) { + return ( + type?.kind === 'LIST' || + (type?.kind === 'NON_NULL' && type?.ofType?.kind === 'LIST') + ) +} + export function introspectionQueryOrMutationToResponse({ field, introspectionResponse, @@ -320,7 +327,7 @@ export function introspectionQueryOrMutationToResponse({ } // Fields? OK, it's a complex Object/Type, so we'll have to go through all the top-level fields build an object - return underlyingTypeDefinition.fields.reduce((acc, field) => { + const exampleObject = underlyingTypeDefinition.fields.reduce((acc, field) => { const underlyingTypeDefinition = introspectionManipulator.getType( IntrospectionManipulator.digUnderlyingType(field.type) ) @@ -334,6 +341,8 @@ export function introspectionQueryOrMutationToResponse({ ) return acc }, {}) + + return isList(field.type) ? [exampleObject] : exampleObject } function generateIntrospectionReturnTypeExample(