Skip to content

Commit 3b4d32f

Browse files
authored
fix(gatsby-source-contentful): Correct supported image formats (#29562)
1 parent df2f9d6 commit 3b4d32f

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

packages/gatsby-plugin-image/src/resolver-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export function getGatsbyImageFieldConfig<TSource, TContext>(
176176
The image formats to generate. Valid values are AUTO (meaning the same format as the source image), JPG, PNG, WEBP and AVIF.
177177
The default value is [AUTO, WEBP], and you should rarely need to change this. Take care if you specify JPG or PNG when you do
178178
not know the formats of the source images, as this could lead to unwanted results such as converting JPEGs to PNGs. Specifying
179-
both PNG and JPG is not supported and will be ignored. AVIF support is currently experimental.
179+
both PNG and JPG is not supported and will be ignored.
180180
`,
181181
defaultValue: [`auto`, `webp`],
182182
},

packages/gatsby-source-contentful/src/extend-node-type.js

+20
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
GraphQLFloat,
1313
GraphQLNonNull,
1414
GraphQLJSON,
15+
GraphQLList,
1516
} = require(`gatsby/graphql`)
1617
const qs = require(`qs`)
1718
const { generateImageData } = require(`gatsby-plugin-image`)
@@ -33,6 +34,8 @@ const {
3334
// cache is more likely to go stale than the images (which never go stale)
3435
// Note that the same image might be requested multiple times in the same run
3536

37+
const validImageFormats = new Set([`jpg`, `png`, `webp`])
38+
3639
if (process.env.GATSBY_REMOTE_CACHE) {
3740
console.warn(
3841
`Note: \`GATSBY_REMOTE_CACHE\` will be removed soon because it has been renamed to \`GATSBY_CONTENTFUL_EXPERIMENTAL_REMOTE_CACHE\``
@@ -200,6 +203,13 @@ const generateImageSource = (
200203
height = CONTENTFUL_IMAGE_MAX_SIZE
201204
}
202205

206+
if (!validImageFormats.has(toFormat)) {
207+
console.warn(
208+
`[gatsby-source-contentful] Invalid image format "${toFormat}". Supported types are jpg, png and webp"`
209+
)
210+
return undefined
211+
}
212+
203213
const src = createUrl(filename, {
204214
width,
205215
height,
@@ -781,6 +791,16 @@ exports.extendNodeType = ({ type, store, reporter }) => {
781791
type: GraphQLInt,
782792
defaultValue: 50,
783793
},
794+
formats: {
795+
type: GraphQLList(ImageFormatType),
796+
description: stripIndent`
797+
The image formats to generate. Valid values are AUTO (meaning the same format as the source image), JPG, PNG, and WEBP.
798+
The default value is [AUTO, WEBP], and you should rarely need to change this. Take care if you specify JPG or PNG when you do
799+
not know the formats of the source images, as this could lead to unwanted results such as converting JPEGs to PNGs. Specifying
800+
both PNG and JPG is not supported and will be ignored.
801+
`,
802+
defaultValue: [``, `webp`],
803+
},
784804
})
785805

786806
fieldConfig.type = GraphQLJSON

packages/gatsby-source-contentful/src/schemes.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const ImageFormatType = new GraphQLEnumType({
44
name: `ContentfulImageFormat`,
55
values: {
66
NO_CHANGE: { value: `` },
7+
AUTO: { value: `` },
78
JPG: { value: `jpg` },
89
PNG: { value: `png` },
910
WEBP: { value: `webp` },

0 commit comments

Comments
 (0)