From 428df2436a149b5d083a8e7443bd37cd8a6a36bc Mon Sep 17 00:00:00 2001 From: YannickMol Date: Thu, 15 Apr 2021 01:03:39 +0200 Subject: [PATCH] Add Gatsby Image to package (#5010) Co-authored-by: Rijk van Zanten --- .../gatsby-source-directus/gatsby-node.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/packages/gatsby-source-directus/gatsby-node.js b/packages/gatsby-source-directus/gatsby-node.js index 3c301427a2..6688ab8c2a 100644 --- a/packages/gatsby-source-directus/gatsby-node.js +++ b/packages/gatsby-source-directus/gatsby-node.js @@ -1,6 +1,8 @@ const invariant = require('invariant'); const Directus = require('@directus/sdk-js'); const { sourceNodes } = require('@lnfusion/gatsby-source-graphql'); +const { createRemoteFileNode } = require("gatsby-source-filesystem"); + const ms = require('ms'); const chalk = require('chalk'); @@ -158,3 +160,42 @@ exports.sourceNodes = async (gatsby, options) => { headers, }); }; + +/** + * Gatsby file implementation. + */ + exports.createResolvers = async ({ + actions, + cache, + createNodeId, + createResolvers, + store, + reporter, + }, options) => { + const { createNode } = actions; + + const { url } = options; + + let endpoints = normalizeEndpoint(url); + + await createResolvers({ + DirectusData_directus_files: { + imageFile: { + type: "File", + async resolve(source) { + if (!source || !source.id) { + return null; + } + return await createRemoteFileNode({ + url: `${endpoints.base}assets/${source.id}`, + store, + cache, + createNode, + createNodeId, + reporter, + }); + }, + }, + }, + }); + };