Skip to content

Commit

Permalink
Return an array if the object is a list (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
jocrau authored May 9, 2022
1 parent 9ada502 commit 129a3c4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
)
Expand All @@ -334,6 +341,8 @@ export function introspectionQueryOrMutationToResponse({
)
return acc
}, {})

return isList(field.type) ? [exampleObject] : exampleObject
}

function generateIntrospectionReturnTypeExample(
Expand Down

0 comments on commit 129a3c4

Please sign in to comment.