I am trying to understand how StaticQuery works in a Gatsby/GraphQL workflow, and as a trial I want to build an article header with a background image.
The image is defined in frontmatter of the markdown file I am building from (frontmatter.feature
).
I know the nature of StaticQuery is... well... static, so I cannot pass dynamic variables to a query. But that's not what I am doing - I think.
Here's my example:
articleHeader(frontmatter) {
if (frontmatter.feature) {
return (
<StaticQuery
query={graphql`
query($base: String!) {
file(base: { eq: $base }) {
publicURL
}
}
`}
render={data => (
<ArticleHeader
style={"background-image:url(" + data.file.publicURL + ")"}
>
<Heading>{frontmatter.title}</Heading>
</ArticleHeader>
)}
/>
);
} else return <Heading>{frontmatter.title}</Heading>;
}
My problem is that I want to pass frontmatter.feature
to my query so that I can query for base: { eq: $base }
... but how?
Note: I've set up plugins properly, and I can query for files through the graphiql interface without issues.