angeloocana / gatsby-plugin-i18n

Multi language routes for Gatsby
435 stars 77 forks source link

Custom fields are not under 'node.fields' available but under 'node.frontmatter' #125

Open zeekrey opened 4 years ago

zeekrey commented 4 years ago

I created a new project based on https://github.com/gatsbyjs/gatsby/tree/master/examples/using-markdown-pages

After I added gatsby-plugin-i18n the following errors occurs:

File: node_modules/gatsby-plugin-i18n/createPages.js:46:10

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
gatsby-plugin-i18n error:
[
  GraphQLError: Cannot query field "fields" on type "MarkdownRemark".
      at Object.Field (/private/tmp/gatsby/examples/using-markdown-pages/node_modules/graphql/validation/rules/FieldsOnCorrectType.js:53:31)
      at Object.enter (/private/tmp/gatsby/examples/using-markdown-pages/node_modules/graphql/language/visitor.js:324:29)
      at Object.enter (/private/tmp/gatsby/examples/using-markdown-pages/node_modules/graphql/language/visitor.js:375:25)
      at visit (/private/tmp/gatsby/examples/using-markdown-pages/node_modules/graphql/language/visitor.js:242:26)
      at validate (/private/tmp/gatsby/examples/using-markdown-pages/node_modules/graphql/validation/validate.js:73:24)
      at GraphQLRunner.validate (/private/tmp/gatsby/examples/using-markdown-pages/node_modules/gatsby/dist/query/graphql-runner.js:82:44)
      at GraphQLRunner.query (/private/tmp/gatsby/examples/using-markdown-pages/node_modules/gatsby/dist/query/graphql-runner.js:146:25)
      at /private/tmp/gatsby/examples/using-markdown-pages/node_modules/gatsby/dist/bootstrap/create-graphql-runner.js:25:37
      at /private/tmp/gatsby/examples/using-markdown-pages/node_modules/gatsby-plugin-i18n/createPages.js:49:5
      at new Promise (<anonymous>)
      at Object.createPages (/private/tmp/gatsby/examples/using-markdown-pages/node_modules/gatsby-plugin-i18n/createPages.js:46:10)
      at runAPI (/private/tmp/gatsby/examples/using-markdown-pages/node_modules/gatsby/dist/utils/api-runner-node.js:256:37)
      at Promise.catch.decorateEvent.pluginName (/private/tmp/gatsby/examples/using-markdown-pages/node_modules/gatsby/dist/utils/api-runner-node.js:375:15)
      at Promise._execute (/private/tmp/gatsby/examples/using-markdown-pages/node_modules/bluebird/js/release/debuggability.js:384:9)
      at Promise._resolveFromExecutor (/private/tmp/gatsby/examples/using-markdown-pages/node_modules/bluebird/js/release/promise.js:518:18)
      at new Promise (/private/tmp/gatsby/examples/using-markdown-pages/node_modules/bluebird/js/release/promise.js:103:10) {
    message: 'Cannot query field "fields" on type "MarkdownRemark".',
    locations: [ [Object] ]
  }
]
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

It looks like gatsby-transformer-remark puts custom fields under node.frontmatter. At least there is no node called node.fields. After installing gatsby-plugin-i18n nothing actually happened. I looked into the source code and saw, that getMarkdownPage.js expects a node called node.fields.slug and node.fields.langKey. But at least in the graphql explorer I can't find this data.

Does anybody know how to fix this?

zeekrey commented 4 years ago

Sorry, I missed the graphql query in the config object. I changed it:

markdownRemark: {
          postPage: 'src/templates/blogTemplate.js',
          query: `
            {
              allMarkdownRemark {
                edges {
                  node {
                    frontmatter {
                      slug,
                      langKey
                    }
                  }
                }
              }
            }
          `
        }

But still, nothing happens. If I look at the page sitemap, there are no routes for the actual language keys.