i'm trying to add an searchindex at buildtime in my gatsby + apollo project.
I tried following following this article:
- using the standard lunr package https://css-tricks.com/how-to-add-lunr-search-to-your-gatsby-website/
I get stuck because in the example they are using the MarkdownRemark integrated in the gatsby starter. However I want to use the data I fetched from Apollo (using gatsby-source-graphql).
My query that I need to fetch looks something like this:
{
apollo {
allExampleData {
name
...
}
}
}
The turorial uses the context.nodeModel to fetch the MarkdownRemark which are all separate nodes. In my case there is 1 GraphQLSource node (= apollo) and several collections under it (fe: allExampleData). When trying to fetch the GraphQLSource I don't see any children.
Code I use to fetch the data:
// gatsby-node.js
exports.createResolvers = ({ cache, createResolvers }) => {
createResolvers({
Query: {
LunrIndex: { // = name of the index
type: GraphQLJSONObject,
resolve: (source, args, context, info) => {
// fetching apollo node
const apolloNode = context.nodeModel.getAllNodes({
type: `GraphQLSource`,
})
// ... create index etc ...
}
}
})
This is the response I see of variable apolloNode:
// console.log(apolloNode)
{
id: '6b0123db-62eb-5c8c-9465-c75ecc7526f9',
typeName: 'Apollo',
fieldName: 'apollo',
parent: null,
children: [],
internal: {
type: 'GraphQLSource',
contentDigest: '0380f5a271ee2bec2ab7a95ec173714a',
ignoreType: true,
counter: 55,
owner: 'gatsby-source-graphql'
}
}
Is there any way to fetch the underlying allIndustries based on this? Or is there another way I can push data during build time into lunr?