I am trying to query custom fields on a specific page and not all pages. The site runs on Gatsby which is connected to WordPress. Like from the Gatsby docs I have the following queries in my algolia-queries.js
file.
const aboutSnipQuery = `{
wpPage (title: {eq: "About"}) {
about {
section1 {
copy
}
section2 {
copy
}
section3 {
copy
}
section4 {
copy
}
team {
copy
}
}
}
}`
const productSnipQuery = `{
wpPage (title: {eq: "Product"}) {
product {
product {
banner {
copy
}
cta {
copy
}
section3 {
copy
}
section4 {
copy
}
section5 {
copy
}
sectionScale {
copy
}
}
}
}
}`
Which feeds into these transformers.
/** The transformer converts the GraphQL Query into a Algolia Record */
const queries = [
{
query: aboutSnipQuery,
transformer: ({ data }) =>
Object.keys(data.wpPage.about).map((section, i=0) => ({
objectID: i+1,
title: "About",
pageType: "aboutPage",
blurb: data.wpPage.about[section].copy,
slug: '/about/',
})),
indexName: process.env.GATSBY_ALGOLIA_INDEX_NAME,
enablePartialUpdates: true,
settings: { attributesToSnippet: [`blurb:20`],
searchableAttributes: ['title', 'blurb', 'terms.name'],
attributesForFaceting: ['pageType']},
},
{
query: productSnipQuery,
transformer: ({ data }) =>
Object.keys(data.wpPage.product.product).map((block, p=0) => ({
objectID: p+1,
title: "Product",
pageType: "productPage",
blurb: data.wpPage.product.product[block].copy,
slug: '/product/',
})),
indexName: process.env.GATSBY_ALGOLIA_INDEX_NAME,
enablePartialUpdates: true,
settings: { attributesToSnippet: [`blurb:20`],
searchableAttributes: ['title', 'blurb', 'terms.name'],
attributesForFaceting: ['pageType']},
},
]
module.exports = queries
The expected result is that I would get records created from objects from both queries. The actual result is that I only get results from the last query. I can switch the queries and still get records from the last result.
My thoughts is that algolia-queries.js
will only recognize one wpPage
query. It it possible to do multiple queries like this?