I would like to have createPages do something like this in my gatsby-node.js
exports.createPages = ({ boundActionCreators, graphql }) => {
const { createPage } = boundActionCreators;
create IndexPageA(createPage, graphql, 'A');
create IndexPageB(createPage, graphql, 'B');
create IndexPageC(createPage, graphql, 'C');
};
The 'A' , 'B', 'C' need to be passed on to the same graphQL query
I tried something like below, but it didn't work ...
I get the error -> GraphQLError: Variable "$indexPage" of required type "String!" was not provided.
How do I pass the string to the query when I invoke the query in gatsby-node.js?
const createIndexPage = (createPage, graphql, indexPage) => {
return new Promise((resolve, reject) => {
...
resolve(
graphql(
`
query TrekByIndex($indexPage: String!)
{
allMarkdownRemark(filter: {fields: {slug: { regex: $indexPage }}}) {
edges {
node {
...
}
}
}
}
`
).then(result => {
...
createPage({
...
});
})
);
});
}
you should be able to pass second paramater to graphql
function with context (values available as parameters):
graphql(`<your_query_with_variable>`, { indexPage: <value_of_variable> })
@pieh Yes it works like a charm! Thank you.
Most helpful comment
you should be able to pass second paramater to
graphql
function with context (values available as parameters):