From bdfcdd470f7af7e99e74bf7b9f4fa0bae189b5f8 Mon Sep 17 00:00:00 2001 From: axe312ger Date: Fri, 25 Mar 2022 15:21:50 +0100 Subject: [PATCH] fix: allow assets without files for preview --- .../create-schema-customization.js.snap | 2 +- .../src/create-schema-customization.js | 54 ++++++++++--------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/packages/gatsby-source-contentful/src/__tests__/__snapshots__/create-schema-customization.js.snap b/packages/gatsby-source-contentful/src/__tests__/__snapshots__/create-schema-customization.js.snap index 96b783fd4e6de..fdf69748fd88a 100644 --- a/packages/gatsby-source-contentful/src/__tests__/__snapshots__/create-schema-customization.js.snap +++ b/packages/gatsby-source-contentful/src/__tests__/__snapshots__/create-schema-customization.js.snap @@ -215,7 +215,7 @@ Ignored if layout = FLUID.", }, }, "resolve": [Function], - "type": "JSON!", + "type": "JSON", }, "height": Object { "type": "Int", diff --git a/packages/gatsby-source-contentful/src/create-schema-customization.js b/packages/gatsby-source-contentful/src/create-schema-customization.js index fecba72ebcd57..155a34a553dbf 100644 --- a/packages/gatsby-source-contentful/src/create-schema-customization.js +++ b/packages/gatsby-source-contentful/src/create-schema-customization.js @@ -326,6 +326,33 @@ export async function createSchemaCustomization( ) // Assets + const gatsbyImageData = getGatsbyImageFieldConfig( + async (...args) => resolveGatsbyImageData(...args, { cache }), + { + jpegProgressive: { + type: `Boolean`, + defaultValue: true, + }, + resizingBehavior: { + type: ImageResizingBehavior, + }, + cropFocus: { + type: ImageCropFocusType, + }, + cornerRadius: { + type: `Int`, + defaultValue: 0, + description: stripIndent` + Desired corner radius in pixels. Results in an image with rounded corners. + Pass \`-1\` for a full circle/ellipse.`, + }, + quality: { + type: `Int`, + defaultValue: 50, + }, + } + ) + gatsbyImageData.type = `JSON` createTypes( addRemoteFilePolyfillInterface( schema.buildObjectType({ @@ -334,32 +361,7 @@ export async function createSchemaCustomization( id: { type: `ID!` }, sys: { type: `ContentfulSys!` }, metadata: { type: `ContentfulMetadata!` }, - gatsbyImageData: getGatsbyImageFieldConfig( - async (...args) => resolveGatsbyImageData(...args, { cache }), - { - jpegProgressive: { - type: `Boolean`, - defaultValue: true, - }, - resizingBehavior: { - type: ImageResizingBehavior, - }, - cropFocus: { - type: ImageCropFocusType, - }, - cornerRadius: { - type: `Int`, - defaultValue: 0, - description: stripIndent` - Desired corner radius in pixels. Results in an image with rounded corners. - Pass \`-1\` for a full circle/ellipse.`, - }, - quality: { - type: `Int`, - defaultValue: 50, - }, - } - ), + gatsbyImageData, ...(pluginConfig.get(`downloadLocal`) ? { localFile: {