Skip to content

Commit

Permalink
poc
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdz committed Jan 6, 2021
1 parent c8cdb07 commit 0291b50
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions packages/gatsby/src/schema/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,22 +370,35 @@ export function fileByPath<TSource, TArgs>(
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)
}
}

Expand Down

0 comments on commit 0291b50

Please sign in to comment.