whoisryosuke / gatsby-documentation-starter

Automatically generate docs for React components using MDX, react-docgen, and GatsbyJS
https://gatsby-documentation-starter.netlify.com/
MIT License
91 stars 13 forks source link

GraphQLError: Cannot query field "allMdx" on type "Query". #3

Closed mcconkiee closed 5 years ago

mcconkiee commented 6 years ago

Hi, i'm getting the following error on vanilla install...I've followed the docs as the read for adding to an existing project - My project does not have any mdx files, only js....is that my issue?

Let me know what else i can provide.

⠁ [ { GraphQLError: Cannot query field "allMdx" on type "Query".
    at Object.Field (/Users/em/Documents/work/Daikin/daikin-ssr-app/docs/node_modules/graphql/validation/rules/FieldsOnCorrectType.js:65:31)
    at Object.enter (/Users/em/Documents/work/Daikin/daikin-ssr-app/docs/node_modules/graphql/language/visitor.js:324:29)
    at Object.enter (/Users/em/Documents/work/Daikin/daikin-ssr-app/docs/node_modules/graphql/language/visitor.js:366:25)
    at visit (/Users/em/Documents/work/Daikin/daikin-ssr-app/docs/node_modules/graphql/language/visitor.js:254:26)
    at visitUsingRules (/Users/em/Documents/work/Daikin/daikin-ssr-app/docs/node_modules/graphql/validation/validate.js:74:22)
    at validate (/Users/em/Documents/work/Daikin/daikin-ssr-app/docs/node_modules/graphql/validation/validate.js:59:10)
    at graphqlImpl (/Users/em/Documents/work/Daikin/daikin-ssr-app/docs/node_modules/graphql/graphql.js:106:50)
    at /Users/em/Documents/work/Daikin/daikin-ssr-app/docs/node_modules/graphql/graphql.js:66:223
    at Promise._execute (/Users/em/Documents/work/Daikin/daikin-ssr-app/docs/node_modules/bluebird/js/release/debuggability.js:313:9)
    at Promise._resolveFromExecutor (/Users/em/Documents/work/Daikin/daikin-ssr-app/docs/node_modules/bluebird/js/release/promise.js:483:18)
    at new Promise (/Users/em/Documents/work/Daikin/daikin-ssr-app/docs/node_modules/bluebird/js/release/promise.js:79:10)
    at graphql (/Users/em/Documents/work/Daikin/daikin-ssr-app/docs/node_modules/graphql/graphql.js:63:10)
    at graphqlRunner (/Users/em/Documents/work/Daikin/daikin-ssr-app/docs/node_modules/gatsby/dist/bootstrap/index.js:300:14)
    at Promise (/Users/em/Documents/work/Daikin/daikin-ssr-app/docs/gatsby-node.js:14:7)
    at Promise._execute (/Users/em/Documents/work/Daikin/daikin-ssr-app/docs/node_modules/bluebird/js/release/debuggability.js:313:9)
    at Promise._resolveFromExecutor (/Users/em/Documents/work/Daikin/daikin-ssr-app/docs/node_modules/bluebird/js/release/promise.js:483:18)
    message: 'Cannot query field "allMdx" on type "Query".',
    locations: [ [Object] ],
    path: undefined } ]
error gatsby-node.js returned an error
smakosh commented 5 years ago

You should create the mdx files for each component and make sure you have the right path on your gatsby-config file

tgallacher commented 5 years ago

Hi @mcconkiee. It appears that by default gatsby-mdx only looks for files with extension .mdx. If you only have .md files, this error is thrown: I think this is due to the fact the plugin fails to find any nodes on your filesystem (i.e. no .mdx files).

To solve this you can either:

  1. Rename all .md files to .mdx, or
  2. Update the gatsby-mdx config to tell it to look for .md files as well. In your gatsby-config.js, add the extensions option to the gatsby-mdx plugin:
// ... other plugins
{
  resolve: 'gatsby-mdx',
  options: {
    extensions: ['.mdx', '.md'],
  },
},

See: https://gatsby-mdx.netlify.com/api-reference/options/extensions

Credit to this repo, where i first discovered the extensions config option and which led me to track down the official docs above: https://github.com/daneden/daneden.me/blob/master/gatsby-config.js

whoisryosuke commented 5 years ago

@tgallacher cleared this up 👏 thanks

You have to have MDX files to use MDX, it doesn't support regular MD files at the moment. It's the only thing preventing this theme from being a complete "drop-in" solution for most component libraries that use standard MD files for docs (albeit not that much of a limitation mass-renaming).

Closing this for now, but I'll make sure to try to clarify it in the README that MD files are not read. If anyone has any recommendations, please feel free to fork the README 👍