@@ -12,6 +12,7 @@ const {
12
12
GraphQLFloat,
13
13
GraphQLNonNull,
14
14
GraphQLJSON,
15
+ GraphQLList,
15
16
} = require ( `gatsby/graphql` )
16
17
const qs = require ( `qs` )
17
18
const { generateImageData } = require ( `gatsby-plugin-image` )
@@ -33,6 +34,8 @@ const {
33
34
// cache is more likely to go stale than the images (which never go stale)
34
35
// Note that the same image might be requested multiple times in the same run
35
36
37
+ const validImageFormats = new Set ( [ `jpg` , `png` , `webp` ] )
38
+
36
39
if ( process . env . GATSBY_REMOTE_CACHE ) {
37
40
console . warn (
38
41
`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 = (
200
203
height = CONTENTFUL_IMAGE_MAX_SIZE
201
204
}
202
205
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
+
203
213
const src = createUrl ( filename , {
204
214
width,
205
215
height,
@@ -781,6 +791,16 @@ exports.extendNodeType = ({ type, store, reporter }) => {
781
791
type : GraphQLInt ,
782
792
defaultValue : 50 ,
783
793
} ,
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
+ } ,
784
804
} )
785
805
786
806
fieldConfig . type = GraphQLJSON
0 commit comments