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

Remove _openAPIToGraphQL from arbitrary JSON in arrays #450

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions packages/openapi-to-graphql/src/schema_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@ const CleanGraphQLJSON = new GraphQLScalarType({
cleanValue = { ...value }

delete cleanValue[OPENAPI_TO_GRAPHQL]
} else if (
/**
* As an exception to the above case an object may be an array defined as an object
* where the array members contain an arbitrary JSON and *do* have the
* _openAPIToGraphQL field which must be removed
*/
value &&
typeof value === 'object' &&
value.length > 0 &&
typeof value[0] == 'object' &&
typeof value[0][OPENAPI_TO_GRAPHQL] === 'object'
) {
cleanValue = value.map((member) => {
const cleanmember = { ...member }
delete cleanmember[OPENAPI_TO_GRAPHQL]
return cleanmember
})

/**
* As a GraphQLJSON type, the value can also be a scalar or array or
Expand Down