UNPKG

981 BJavaScriptView Raw
1const { supportedExtensions } = require(`./supported-extensions`)
2
3module.exports = ({ createResolvers, reporter }, pluginOptions = {}) => {
4 const { checkSupportedExtensions = true } = pluginOptions
5
6 const resolvers = {
7 File: {
8 childImageSharp: {
9 resolve: (parent, args, context, info) => {
10 // TODO: In future when components from GraphQL are possible make sure that we can support both supported & unsupported image formats
11 if (
12 !supportedExtensions[parent.extension] &&
13 checkSupportedExtensions
14 ) {
15 reporter.warn(
16 `You can't use childImageSharp together with ${parent.name}.${parent.extension} — use publicURL instead. The childImageSharp portion of the query in this file will return null:\n${context.componentPath}`
17 )
18 }
19 return info.originalResolver(parent, args, context, info)
20 },
21 },
22 },
23 }
24
25 createResolvers(resolvers)
26}