prismic-gatsby: Unable to pull data from group containing content relationships
I have a content type of ‘Location’, which holds a group of content relationships to a content type of ‘Project’. (E.g. the “New York” location holds around 10 “Projects”.)
-
I have no problem fetching the correct data via GraphiQL… but it errors out when compiling with the same query.
-
I have no trouble pulling the data when the content relationship is 1:1… things compile fine.
This is my query in gatsby-node.js.
const projectsByLocation = await graphql(`
{
allPrismicLocations {
edges {
node {
uid
data {
projects {
project {
document {
uid
}
}
}
title {
text
}
}
}
}
}
}
`);
(This works perfectly in GraphiQL… but fails on compile with an error message of: "TypeError: Cannot read property ‘allPrismicLocations’ of undefined.)
And removing
projects {
project {
document {
uid
}
}
}
allows it to compile fine, but with no project data.
Is this a limitation, or am I doing something incorrectly? Sorry - my brain is mush after trying to solve this for the past 7 hours.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 24 (11 by maintainers)
@Hahlh Great, glad to hear it’s working!
The next major version of the plugin will tell you if you’re missing a schema to help others in the future. Something like the following will be printed when running
gatsby develop:@angeloashmore , you are great!
This is the second time that not adding the schema to gatsby-config.js was the cause of an issue.
Thank you for your fast response and your help!
@Hahlh Can you double check that you added your
pagecustom type JSON schema togatsby-config.js?It looks like Gatsby is inferring the types, so it doesn’t know that “PrismicPage” is a Prismic document.
You should be providing it to the
schemasoption like the following:@jordyvanraaij (or maybe @angeloashmore) Did you find a fix for this at some point or realized where you went wrong?
I am currently facing the exact same issue.
After having created a single type for a page, I added two content relationship for selecting two featured articles, but I am unable to see “document” as a query option.
I double checked the schemas several times, experimented with using selection fields instead and tried to use prismicHome, but all to no avail.
I also can’t access “document” if I look at dataRaw instead.
What am I missing?
I would be thankful if someone could point me in the right direction.
I’m having a very similar issue.
I have a group containing only content relationships (restricted to a single type), but in GraphiQL and Gatsby, each item is missing the
documentproperty. As was the case for @stoutlabs, 1:1 content relationships work fine.Knowing that
plansis a group of pricing_plan andrecommended_planis a single pricing_plan :Here is the query in GraphiQL
The fields in Prismic
The PricingTab fields in our redux-state.json
And one PricingPlan from our same redux-state.json
Any ideas are welcome, as this is pretty much a blocking issue for us.
Thanks!