gatsby-source-prismic-graphql icon indicating copy to clipboard operation
gatsby-source-prismic-graphql copied to clipboard

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

Open ajz003 opened this issue 4 years ago • 6 comments

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?

ajz003 avatar May 02 '20 18:05 ajz003

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?

noblica avatar May 15 '20 12:05 noblica

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.

meandillar avatar May 16 '20 03:05 meandillar

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

wooxudong avatar May 18 '20 03:05 wooxudong

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

noblica avatar May 18 '20 12:05 noblica

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

hs737 avatar May 19 '20 16:05 hs737

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!

noblica avatar May 19 '20 21:05 noblica