prismicio / gatsby-source-prismic-graphql

Gatsby source plugin for Prismic GraphQL
MIT License
17 stars 14 forks source link

Custom type naming conventions (error while running the createPages lifecycle) #42

Open Jussiles opened 4 years ago

Jussiles commented 4 years ago

After updating Gatsby from 2.21.9 I started getting this error. Then I updated also gatsby-source-prismic-graphql plugin from 3.6.2 to use this repo and latest tag 3.6.11. Error still exists. Happens on running gatsby develop or gatsby build:

ERROR #11321  PLUGIN

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

Unknown type "PRISMIC_SortPagecorey". Did you mean "PRISMIC_SortPageCorey", "PRISMIC_SortPagey", "PRISMIC_PageCore", "PRISMIC_WherePageCore", or "PRISMIC_SortCorePagey"?

  260 |                         });
  261 |                         _context.next = 10;
  262 |                         return graphql(query, {
      |                                ^
  263 |                           after: endCursor,
  264 |                           lang: lang || null,
  265 |                           sortBy: page.sortBy

File: node_modules/@prismicio/gatsby-source-prismic-graphql/gatsby-node.js:262:32

Error: Unknown type "PRISMIC_SortPagecorey". Did you mean "PRISMIC_SortPageCorey", "PRISMIC_SortPagey", "PRISMIC_PageCore", "PRISMIC_WherePageCo  re", or "PRISMIC_SortCorePagey"?
  GraphQL request:2:64
  1 |
  2 |   query AllPagesQuery ($after: String, $lang: String, $sortBy: PRISMIC_SortPagecorey) {
    |                                                                ^
  3 |     prismic {

  - graphql-runner.ts:98 GraphQLRunner.validate
    [packx-marketing]/[gatsby]/src/query/graphql-runner.ts:98:22

  - graphql-runner.ts:162 GraphQLRunner.query
    [packx-marketing]/[gatsby]/src/query/graphql-runner.ts:162:25

  - create-graphql-runner.ts:59
    [packx-marketing]/[gatsby]/src/bootstrap/create-graphql-runner.ts:59:8

  - gatsby-node.js:262 _callee$
    [packx-marketing]/[@prismicio]/gatsby-source-prismic-graphql/gatsby-node.js:262:32

  - new Promise

  - From previous event:

  - api-runner-node.js:440 Promise.catch.decorateEvent.pluginName
    [packx-marketing]/[gatsby]/src/utils/api-runner-node.js:440:9

  - From previous event:

  - api-runner-node.js:439
    [packx-marketing]/[gatsby]/src/utils/api-runner-node.js:439:14

  - timers.js:439 processImmediate
    internal/timers.js:439:21

  - From previous event:

  - api-runner-node.js:431
    [packx-marketing]/[gatsby]/src/utils/api-runner-node.js:431:13

  - From previous event:

  - api-runner-node.js:347 module.exports
    [packx-marketing]/[gatsby]/src/utils/api-runner-node.js:347:3

  - create-pages.ts:25 createPages
    [packx-marketing]/[gatsby]/src/services/create-pages.ts:25:9

  - interpreter.js:721 Interpreter.exec
    [packx-marketing]/[gatsby]/[xstate]/lib/interpreter.js:721:27

  - interpreter.js:223 Interpreter.execute
    [packx-marketing]/[gatsby]/[xstate]/lib/interpreter.js:223:22

  - interpreter.js:243 Interpreter.update
    [packx-marketing]/[gatsby]/[xstate]/lib/interpreter.js:243:18

  - interpreter.js:144
    [packx-marketing]/[gatsby]/[xstate]/lib/interpreter.js:144:23

  - scheduler.js:59 Scheduler.process
    [packx-marketing]/[gatsby]/[xstate]/lib/scheduler.js:59:13

  - scheduler.js:43 Scheduler.schedule
    [packx-marketing]/[gatsby]/[xstate]/lib/scheduler.js:43:14

  - interpreter.js:140 Interpreter.send
    [packx-marketing]/[gatsby]/[xstate]/lib/interpreter.js:140:29

  - interpreter.js:836 actor.id
    [packx-marketing]/[gatsby]/[xstate]/lib/interpreter.js:836:23

failed createPages - 0.191s

This is my gatsby-config.js:

      resolve: '@prismicio/gatsby-source-prismic-graphql',
      options: {
        accessToken: '${process.env.PRISMIC_API_KEY}',
        repositoryName: '${process.env.PRISMIC_REPOSITORY_NAME}',
        defaultLang: defaultLanguage.locale,
        langs: Object.values(languages).map(lang => lang.locale),
        shortenUrlLangs: true,
        path: '/preview',
        previews: true,
        pages: [
          {
            type: 'PageCore',
            match: '/:lang/:uid',
            previewPath: '/preview-pagecore',
            filter: data =>
              !isDummy(data.node._meta) &&
              !['index', 'home'].includes(data.node._meta.uid),
            component: require.resolve('./src/templates/pageCore.js'),
            sortBy: 'date_ASC',
          },
          {
            type: 'Page',
            match: '/:lang/:uid',
            previewPath: '/preview-page',
            filter: data =>
              !isDummy(data.node._meta) &&
              !['index', 'home'].includes(data.node._meta.uid),
            component: require.resolve('./src/templates/page.js'),
          },
]

Issue seems to be with PageCore. Type Page works fine.

I found some related issues from old and new repo but didn't find solutions from those. https://github.com/birkir/gatsby-source-prismic-graphql/issues/200#issuecomment-629206830 https://github.com/prismicio/gatsby-source-prismic-graphql/pull/2

Jussiles commented 4 years ago

Seems nobody has been interested in this issue. I will try to take the discussion about naming convention further.

Is there any documentation about how the naming convention should be between Prismic - Prismic GraphQL API - Gatsby (this plugin)?

What worked for our project before on gatsby-config.js (type: PageCore, type: BlogPost…) doesn’t work anymore after the PR (https://github.com/prismicio/gatsby-source-prismic-graphql/pull/2) was merged. I know I could create new Custom type with new API ID as a workaround. But that would require me upgrade our Prismic plan from Starter to Medium to import/export the existing content to the new Custom type. It’s not what I want to do in the first place.

On the Prismic side our Custom type API IDs are: page-core, blog-post…

Should the naming conventions for Custom type be documented somewhere? After it there can be fixes done based on documentation for the plugin if needed.

Thoughts?

MarcMcIntosh commented 4 years ago

Hi @Jussiles

Error: Unknown type "PRISMIC_SortPagecorey". Did you mean "PRISMIC_SortPageCorey", Hmm looks like an error with capitalisation :/

You you provide a recreation of the issue in the examples and open a PR?

If you run into issues creating an example, I recommend using gatsby 2.24.11

petrogad commented 4 years ago

Just hit this too. My prismic content type was labeled: "blog_post", I then attempted to use a config for my page as:

{
    type: 'blog_post',
    path: '/blog/',
    match: '/blog/:uid',
    previewPath: '/blog/',
    component: require.resolve('./src/templates/blogPost.tsx')
}

I also tried types of: "BlogPost", "Blog_Post", "blog_post" and the only type I got to work was "Blog_post".

It seems as if there's an issue with handling _ special and uniquely.