From b594dc82c5aa08e933072ac281be3f84ce9c89f4 Mon Sep 17 00:00:00 2001 From: Christopher Date: Wed, 9 Mar 2022 15:15:58 -0500 Subject: [PATCH] Remove _openAPIToGraphQL from arbitrary JSON in [] Signed-off-by: Christopher --- .../openapi-to-graphql/src/schema_builder.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/openapi-to-graphql/src/schema_builder.ts b/packages/openapi-to-graphql/src/schema_builder.ts index 0475f456..6648dd1f 100644 --- a/packages/openapi-to-graphql/src/schema_builder.ts +++ b/packages/openapi-to-graphql/src/schema_builder.ts @@ -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