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”.)

  1. I have no problem fetching the correct data via GraphiQL… but it errors out when compiling with the same query.

  2. 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)

Most upvoted comments

@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:

 ERROR #11331  PLUGIN

Invalid plugin options for "gatsby-source-prismic":

- JSON schema for "navigation" is missing
- JSON schema for "not_found_page" is missing
- JSON schema for "settings" is missing

not finished load plugins - 0.720s

@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 page custom type JSON schema to gatsby-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 schemas option like the following:

{
  resolve: 'gatsby-source-prismic',
  options: {
    // your other options
    schemas: {
      // your other schemas
      page: require('./src/schemas/page.json'), // Replace the path to the JSON file in your project
    }
  }
}

@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.

image

image

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 document property. As was the case for @stoutlabs, 1:1 content relationships work fine.

Knowing that plans is a group of pricing_plan and recommended_plan is a single pricing_plan :

Here is the query in GraphiQL graphiql

The fields in Prismic prismic_tab

The PricingTab fields in our redux-state.json redux_state_

And one PricingPlan from our same redux-state.json screen shot 2018-09-06 at 4 05 50 pm

Any ideas are welcome, as this is pretty much a blocking issue for us.

Thanks!