From 7ea4514ecbc7935726c83a0b6cc88a8029427d23 Mon Sep 17 00:00:00 2001 From: axe312ger Date: Fri, 25 Mar 2022 15:46:28 +0100 Subject: [PATCH] feat: throw error on reservated field names --- .../src/create-schema-customization.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/gatsby-source-contentful/src/create-schema-customization.js b/packages/gatsby-source-contentful/src/create-schema-customization.js index 155a34a553dbf..084d5210059c2 100644 --- a/packages/gatsby-source-contentful/src/create-schema-customization.js +++ b/packages/gatsby-source-contentful/src/create-schema-customization.js @@ -527,6 +527,13 @@ export async function createSchemaCustomization( if (field.disabled || field.omitted) { return } + if ([`id`, `sys`, `contentfulMetadata`].includes(field.id)) { + // Throw error on reserved field names as the Contenful GraphQL API does: + // https://www.contentful.com/developers/docs/references/graphql/#/reference/schema-generation/fields + throw new Error( + `Unfortunately the field name ${field.id} is reserved. ${contentTypeItem.name}@${contentTypeItem.sys.id}` + ) + } fields[field.id] = translateFieldType(field, schema, createTypes) })