Gatsby to copy PDF files CDN

Hi,

I’m building a website with strapi + gatsby stack. I am using gatsby-source-graphql with strapi graphql setup.

For images. I’m using gatsby-plugin-image which works perfectly to resolve images with tons of configuration and optimization. But I’m not able to resolve pdf files from strapi to my public directory.

Is there any way to resolve them? My strapi setup behind company firewall, so I need to copy pdf files as well to public folder, same as images.

Any ideas?

I solved my problem by myself.

I’m leaving the answer for fellow developers;

//gatsby-node.js
const { createRemoteFileNode } = require(`gatsby-source-filesystem`)

exports.createResolvers = async ({
  actions,
  cache,
  createNodeId,
  createResolvers,
  store,
  reporter,
}) => {
  const { createNode } = actions

  await createResolvers({
    StrapiGQL_UploadFile: {
      resolved: {
        type: 'File',
        async resolve(source, args, context, info) {
          let sourceUrl = `http://localhost:1337${source.url}`
          return await createRemoteFileNode({
            url: encodeURI(sourceUrl),
            store,
            cache,
            createNode,
            createNodeId,
            reporter,
          })
        },
      },
    },
  })
}
//gatsby-config.js
{
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `${__dirname}/src`,
      },
    }
query {
 entityName {
  pdfField {
    url
    resolved {
      publicUrl
    }
  }
 }
}