From 7580dc4bc34a73b41ca1605717d40e9175bcac0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Lucassen?= Date: Wed, 3 Jun 2020 13:21:31 +0200 Subject: [PATCH 1/2] get nodes by type --- README.md | 16 ++++++++++++++++ src/gatsby-node.js | 8 +++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1bba7d1..101c53c 100644 --- a/README.md +++ b/README.md @@ -205,3 +205,19 @@ resolvers : { } ``` Now you can use the `featuredImage` data of `BlogPost` model without including all `Asset` models in the `elasticlunr` index [(see PR #3 for more details)](https://github.com/gatsby-contrib/gatsby-plugin-elasticlunr-search/pull/3). + + +You can now also resolve the gatsby store with ``getNodesByType`` and ``getNodes`` +so the full signature of node resolving is this: +``` +(node, getNode, getNodesByType, getNodes) +``` +Documentation of all node helpers: + +- [getNode](https://www.gatsbyjs.org/docs/node-api-helpers/#getNode) +- [getNodesByType](https://www.gatsbyjs.org/docs/node-api-helpers/#getNodesByType) +- [getNodes](https://www.gatsbyjs.org/docs/node-api-helpers/#getNodes) + + + + diff --git a/src/gatsby-node.js b/src/gatsby-node.js index 367344b..67aba50 100644 --- a/src/gatsby-node.js +++ b/src/gatsby-node.js @@ -41,6 +41,8 @@ const createOrGetIndex = async ( node, cache, getNode, + getNodesByType, + getNodes, server, { fields, resolvers } ) => { @@ -65,7 +67,7 @@ const createOrGetIndex = async ( ...Object.keys(fieldResolvers).reduce((prev, key) => { return { ...prev, - [key]: fieldResolvers[key](pageNode, getNode), + [key]: fieldResolvers[key](pageNode, getNode, getNodesByType, getNodes), } }, {}), } @@ -116,7 +118,7 @@ exports.onCreateNode = ({ node, actions, getNode }, { resolvers, filter }) => { } exports.setFieldsOnGraphQLNodeType = ( - { type, getNode, cache }, + { type, getNode, getNodesByType, getNodes, cache }, pluginOptions ) => { if (type.name !== SEARCH_INDEX_TYPE) { @@ -127,7 +129,7 @@ exports.setFieldsOnGraphQLNodeType = ( index: { type: SearchIndex, resolve: (node, _opts, _3, server) => - createOrGetIndex(node, cache, getNode, server, pluginOptions), + createOrGetIndex(node, cache, getNode, getNodesByType, getNodes, server, pluginOptions), }, } } From 920994a3f535224612ca87af15b4180d3e3b497e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Lucassen?= Date: Wed, 3 Jun 2020 14:39:20 +0200 Subject: [PATCH 2/2] bump minor --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 890edbd..34f2836 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gatsby-contrib/gatsby-plugin-elasticlunr-search", - "version": "2.3.0", + "version": "2.4.0", "description": "Search for gatsby; implemented via elasticlunr.", "main": "n/a", "scripts": {