Allow resolving populated nodes
If a node is using a mapping field to be able to map the IDs of a node to a different node type:
"MarkdownRemark.frontmatter.authors": `AuthorsJson`
It would be great to be able to resolve based on the populated object rather than the string:
resolvers: {
// For any node of type MarkdownRemark, list how to resolve the fields' values
MarkdownRemark: {
/**
* It would be nice to get the full `author` object here
* As-of now it is only an array of strings due to the `mapping` not being present
*/
authors: node => node.frontmatter.authors.map(author => author.name).join(', ')
},
},
Seconding this, it'd be great to have fully mapped nodes passed into resolvers. Furthermore, it looks like the call to the resolver function only passes getNode in as an additional parameter, which make it almost impossible to fetch related nodes that have auto-generated IDs, unless you handle this particular use case in advance.
(It would be relatively easy to pass getNodes in as well, but it wouldn't solve the main problem here.)
Is this why excerpts doesn't get indexed?
I have the following in my config
resolvers: {
MarkdownRemark: {
id: ({ id }) => id,
path: ({ fields: { path } }) => path,
title: ({ frontmatter: { title } }) => title,
section: ({ fields: { section } }) => section,
excerpt: ({ excerpt }) => excerpt, // does not seem to be working.
content: ({ rawMarkdownBody }) => rawMarkdownBody
}
},
and everything loads fine but the excerpt is ''
I'm currently stuck with what is probably closely related to this: the plugin does not support linked nodes generated with gatsby-source-contentful. So this can't be done:
resolvers: {
ContentfulFaq: {
title: (node) => node.question, // works, because it's a simple text field
content: (node) => node.answer.answer, // errors, because this is a LongText field which is exposed as an object, and the plugin only sees the unresolved `node.answer___NODE`
supportTopic: (node) => node.supporttopic, // undefined, because this is a reverse reference (it's actually a parent node in Contentful)
keywords: (node) => node.keywords, // works, because it's a simple array
},
},
These fields are however readily available in page & static queries.
See also "A note about LongText fields" and "Notes on Contentful Content Models" on why they are structured like this.
I'm at a loss on how to continue at the moment, any hints would be highly appreciated.
I'm currently having the issue that the featured image of blog search results don't render, because they are usually created by gatsby-transformer-sharp, which populates the MarkdownRemark nodes with special fields. Even though I placed gatsby-plugin-lunr after gatsby-plugin-sharp and gatsby-transformer-sharp in my gatsby-config.js, I can't access those fields in the lunr config resolver.
After 3 years did we never get an answer to this?