Skip to content

Commit

Permalink
Merge pull request #8 from ssfbank/get-nodes-by-type
Browse files Browse the repository at this point in the history
get nodes by type
  • Loading branch information
benabel authored Jun 3, 2020
2 parents 3f3162d + 920994a commit e506cbe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)




2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
8 changes: 5 additions & 3 deletions src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const createOrGetIndex = async (
node,
cache,
getNode,
getNodesByType,
getNodes,
server,
{ fields, resolvers }
) => {
Expand All @@ -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),
}
}, {}),
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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),
},
}
}

0 comments on commit e506cbe

Please sign in to comment.