From 4a743bded97111a859860eedc37f549f6e6580f6 Mon Sep 17 00:00:00 2001 From: Espen Hovlandsdal Date: Mon, 18 Nov 2019 13:46:46 -0800 Subject: [PATCH] [core] GraphQL: Fix top-level references/array types (#1602) --- .../graphql/extractFromSanitySchema.js | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/@sanity/core/src/actions/graphql/extractFromSanitySchema.js b/packages/@sanity/core/src/actions/graphql/extractFromSanitySchema.js index 25845471e4c..9b5e71edd77 100644 --- a/packages/@sanity/core/src/actions/graphql/extractFromSanitySchema.js +++ b/packages/@sanity/core/src/actions/graphql/extractFromSanitySchema.js @@ -28,7 +28,8 @@ function isBaseType(type) { return ( type.name !== type.jsonType && allowedJsonTypes.includes(type.jsonType) && - !skipTypes.includes(type.name) + !skipTypes.includes(type.name) && + !isReference(type) ) } @@ -50,7 +51,15 @@ function isArrayOfBlocks(typeDef) { } function isReference(typeDef) { - return typeDef.name === 'reference' || (typeDef.type && typeDef.type.name === 'reference') + let type = typeDef + while (type) { + if (type.name === 'reference' || (type.type && type.type.name === 'reference')) { + return true + } + + type = type.type + } + return false } function extractFromSanitySchema(sanitySchema) { @@ -108,7 +117,15 @@ function extractFromSanitySchema(sanitySchema) { } function _convertType(type, parent, options) { - const name = type.type ? type.type.name : type.jsonType + let name = type.type ? type.type.name : type.jsonType + + if (isReference(type)) { + name = 'reference' + } + + if (type.jsonType === 'array' || (type.type && type.type.jsonType === 'array')) { + name = 'array' + } switch (name) { case 'document':