From 0291b509805f191adea94e48533f16e35a0d77ae Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Wed, 6 Jan 2021 14:09:04 +0100 Subject: [PATCH] poc --- packages/gatsby/src/schema/resolvers.ts | 41 ++++++++++++++++--------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/packages/gatsby/src/schema/resolvers.ts b/packages/gatsby/src/schema/resolvers.ts index 3253f99d62247..b6fd1c670244e 100644 --- a/packages/gatsby/src/schema/resolvers.ts +++ b/packages/gatsby/src/schema/resolvers.ts @@ -370,22 +370,35 @@ export function fileByPath( node => node.internal && node.internal.type === `File` ) - const findLinkedFileNode = (relativePath: string): any => { - // Use the parent File node to create the absolute path to - // the linked file. - const fileLinkPath = normalize( - systemPath.resolve(parentFileNode.dir, relativePath) - ) - - // Use that path to find the linked File node. - const linkedFileNode = _.find( - context.nodeModel.getAllNodes({ type: `File` }), - n => n.absolutePath === fileLinkPath + if (Array.isArray(fieldValue)) { + return Promise.all( + fieldValue.map(fieldValue => + context.nodeModel.runQuery({ + query: { + filter: { + absolutePath: { + eq: systemPath.resolve(parentFileNode.dir, fieldValue), + }, + }, + }, + firstOnly: true, + type: `File`, + }) + ) ) - return linkedFileNode + } else { + return context.nodeModel.runQuery({ + query: { + filter: { + absolutePath: { + eq: systemPath.resolve(parentFileNode.dir, fieldValue), + }, + }, + }, + firstOnly: true, + type: `File`, + }) } - - return resolveValue(findLinkedFileNode, fieldValue) } }