apollographql / gatsby-theme-apollo

💜 Themes that we use to build Gatsby sites at Apollo
MIT License
371 stars 103 forks source link

Cannot query field "childMarkdownRemark" on type "File". #153

Closed sekoyo closed 4 years ago

sekoyo commented 4 years ago

Hi thanks a lot for this theme. However I'm struggling to get it to run. With the latest gatsby CLI I run gatsby new gatsby-site https://github.com/gatsbyjs/gatsby-starter-hello-world

Then I add this theme and use the default config from this README. Firstly it crashes due to a read failure unless I add some metadata to the config:

siteMetadata: {
    title: '',
    siteName: '',
    description: '',
    author: '',
  },

The next crash is due to this query in template.js:

file(id: {eq: $id}) {
      childMarkdownRemark {
        frontmatter {
          title
          description
        }
        headings {
          value
          depth
        }
        fields {
          image
          apiReference
        }
        htmlAst
      }
      childMdx {
        frontmatter {
          title
          description
        }
        headings {
          value
          depth
        }
        fields {
          image
          apiReference
        }
        body
      }
    }
  }
There was an error in your GraphQL query:

Cannot query field "childMarkdownRemark" on type "File".

If you don't expect "childMarkdownRemark" to exist on the type "File" it is most likely a typo.
However, if you expect "childMarkdownRemark" to exist there are a couple of solutions to common problems:

- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "childMarkdownRemark" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add at least one entry with that field ("dummy content")

It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "File":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions

File: [...]/node_modules/gatsby-theme-apollo-docs/src/components/template.js

And there are indeed no childMarkdownRemark or childMdx fields in file:

Screenshot 2020-10-06 at 23 00 41

Any ideas where I'm going wrong? Thanks

sekoyo commented 4 years ago

Will close as I got it working by cloning a Codesandbox example

sekoyo commented 4 years ago

This error was caused by not having a siteName which is not in your gatsby-config.js snippet in the README.md but it's required and the site crashes without it. Adding siteName in siteMetadata seemed to get passed the issue but it was still crashing but with a more cryptic error 🤦‍♂️

sekoyo commented 4 years ago

P.S. This also throws the same errors if the index file is index.mdx instead of index.md