birkir / gatsby-source-prismic-graphql

Gatsby source plugin for Prismic GraphQL
MIT License
137 stars 75 forks source link

"gatsby-source-prismic-graphql" threw an error while running the createPages lifecycle, related to pages type #200

Open ajz003 opened 4 years ago

ajz003 commented 4 years ago

When running gatsby develop or gatsby build, I get the following error:

 ERROR #11321  PLUGIN

"gatsby-source-prismic-graphql" threw an error while running the createPages lifecycle:

Syntax Error: Expected $, found Name "Posty"

  GraphQLError: Syntax Error: Expected $, found Name "Posty"

  - new Promise

  - graphql-runner.js:38 GraphQLRunner.query
    [react-ajz003]/[gatsby]/dist/query/graphql-runner.js:38:12

failed createPages - 0.071s

I found that the Name "posty" is related to my options in the gatsby-config.js file. Specifically the object defining the type 'Blog Post'.

        pages: [{ // optional
          type: 'Blog Post', // TypeName from prismic
          match: '/article/:uid', // pages will be generated under this pattern
          previewPath: '/article', // optional path for unpublished documents
          component: require.resolve('./src/templates/article.js')
        }]

I created a new custom type on Prismic called Article and used 'Article' in the type field instead, and worked. Is there a problem with having the type be separate words?

noblica commented 4 years ago

I think the problem is in your type name. I had a similar issue, my type was Quick start guide page It seems that the plugin capitalizes only the first letter, and connects the spaces with a _, so what worked for me was changing the type property in the gatsby-config.js, for the gatsby-source-prismic-graphql to Quick_start_guide_page.

So I suggest you try to change your type to Blog_post or Blog_Post, and try again?

meandillar commented 4 years ago

I also experienced this issue and the suggestion above from noblica works - in Prismic the type is ukulele and using Ukulele in gatsby-config.js works.

wooxudong commented 4 years ago

I experienced the same, the prismic type in gatsby-config.js has to start with Capital letter

noblica commented 4 years ago

IMHO, this is undocumented behavior, and should be added to the docs, to avoid further confusion.

hs737 commented 4 years ago

@noblica Thanks for finding the workaround. This needs to at least be documented.

But really, the TypeName as Prismic shows it to users is how users should be expected to put it into the config. It's not ideal/intuitive for users to know that "Blog Post" has to be manually converted to any one of "Blog_Post", "Blog_post", or "blog_post," so that the system recognizes it.

noblica commented 4 years ago

Hey, I made a PR for this issue here: https://github.com/prismicio/gatsby-source-prismic-graphql/pull/2 https://github.com/birkir/gatsby-source-prismic-graphql/pull/214

Hope it's fine. Feel free to provide feedback!