Reputation: 225
I'm creating some landing pages on my Gatsby site and want to list nodes from specific content types. For instance, I have:
allContentfulSongs
allContentfulBlogs
In my landing page template, how can I dynamically query songs or blogs? I tried:
all${landingPage} {
edges {
node {
id
}
}
}
but I'm getting a syntax error. Is there a way to do this in Gatsby or should I just use an
@include(if: $landingPage)
for each contentType in my query?
Upvotes: 0
Views: 515
Reputation: 12625
You cannot use "dynamic" GraphQL queries. So you cannot use a javascript variable as part of your query name in Gatsby.
Queries are treated specially. That's how Gatsby statically compiles your data. Dynamically generated queries would be much harder (or potentially impossible) to cache, so pageQuery
does not allow it.
Upvotes: 3