Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions packages/gatsby-source-drupal/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const {
getExtendedFileNodeData,
} = require(`./utils`)

const imageCdnDocs = `https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-drupal#readme`

const agent = {
http: new HttpAgent(),
https: new HttpsAgent(),
Expand Down Expand Up @@ -680,12 +682,13 @@ ${JSON.stringify(webhookBody, null, 4)}`
}

if (
skipFileDownloads &&
!imageCDNState.foundPlaceholderStyle &&
!imageCDNState.hasLoggedNoPlaceholderStyle
) {
imageCDNState.hasLoggedNoPlaceholderStyle = true
reporter.warn(
`[gatsby-source-drupal]\nNo Gatsby Image CDN placeholder style found. Please ensure that you have a placeholder style in your Drupal site for the fastest builds. See the docs for more info on gatsby-source-drupal Image CDN support:\n\nhttps://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-drupal#readme`
`[gatsby-source-drupal]\nNo Gatsby Image CDN placeholder style found. Please ensure that you have a placeholder style in your Drupal site for the fastest builds. See the docs for more info on gatsby-source-drupal Image CDN support:\n${imageCdnDocs}\n`
)
}

Expand Down Expand Up @@ -857,20 +860,29 @@ exports.onCreateDevServer = async ({ app }) => {
polyfillImageServiceDevRoutes(app)
}

exports.createSchemaCustomization = ({ actions, schema }) => {
actions.createTypes([
// polyfill so image CDN works on older versions of Gatsby
addRemoteFilePolyfillInterface(
// this type is merged in with the inferred file__file type, adding Image CDN support via the gatsbyImage GraphQL field. The `RemoteFile` interface as well as the polyfill above are what add the gatsbyImage field.
schema.buildObjectType({
name: `file__file`,
fields: {},
interfaces: [`Node`, `RemoteFile`],
}),
{
schema,
actions,
}
),
])
exports.createSchemaCustomization = (
{ actions, schema, reporter },
pluginOptions
) => {
if (pluginOptions.skipFileDownloads) {
actions.createTypes([
// polyfill so image CDN works on older versions of Gatsby
addRemoteFilePolyfillInterface(
// this type is merged in with the inferred file__file type, adding Image CDN support via the gatsbyImage GraphQL field. The `RemoteFile` interface as well as the polyfill above are what add the gatsbyImage field.
schema.buildObjectType({
name: `file__file`,
fields: {},
interfaces: [`Node`, `RemoteFile`],
}),
{
schema,
actions,
}
),
])
} else {
reporter.info(
`[gatsby-source-drupal] Enable the skipFileDownloads option to use Gatsby's Image CDN. See the docs for more info:\n${imageCdnDocs}\n`
)
}
}
8 changes: 8 additions & 0 deletions packages/gatsby-source-drupal/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ const getGatsbyImageCdnFields = async ({

return gatsbyImageCdnFields
} catch (e) {
if (e.message.includes(`unrecognized file format`)) {
reporter.error(
`Encountered corrupt file while requesting image dimensions for ${url}`
)

return {}
}

reporter.error(e)
reporter.info(
JSON.stringify(
Expand Down