Skip to content

Instantly share code, notes, and snippets.

@vladar
Created July 8, 2020 16:30
Show Gist options
  • Save vladar/ffcab42fcfa11e2f0fb2125259b1a103 to your computer and use it in GitHub Desktop.
Save vladar/ffcab42fcfa11e2f0fb2125259b1a103 to your computer and use it in GitHub Desktop.
exports.onCreateNode = async ({
node,
actions: { createNode },
createNodeId,
getCache,
}) => {
if (node.remoteTypeName === 'Asset' && node.mimeType.includes('image/')) {
const fileNode = await createRemoteFileNode({
url: node.url,
parentNodeId: node.id,
createNode,
createNodeId,
getCache,
})
if (fileNode) node.remoteFile = fileNode.id
}
}
exports.createSchemaCustomization = ({ actions }) => {
actions.createTypes(`
type GraphCMS_Asset {
remoteFile: File @link
}
`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment