Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a JSON Array for List Return Types #342

Merged
merged 2 commits into from
May 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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