Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown field 'doczDb' on type 'Query' #994

Closed
bryanhidalgo opened this issue Aug 6, 2019 · 17 comments
Closed

Unknown field 'doczDb' on type 'Query' #994

bryanhidalgo opened this issue Aug 6, 2019 · 17 comments
Labels
bug Something isn't working pending-user-response v2

Comments

@bryanhidalgo
Copy link

Bug Report

I keep getting this error when installing the Gatsby theme:

 ERROR #85907  GRAPHQL

There was an error in your GraphQL query:

- Unknown field 'doczDb' on type 'Query'.

File: node_modules/gatsby-theme-docz/src/hooks/useDbQuery.js

Environment

System:
OS: macOS 10.14.5
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.4.1 - /usr/local/bin/node
Yarn: 1.7.0 - /usr/local/bin/yarn
npm: 6.10.2 - /usr/local/bin/npm
Languages:
Python: 2.7.15 - /usr/local/bin/python
Browsers:
Chrome: 75.0.3770.142
Firefox: 68.0
Safari: 12.1.1
npmPackages:
gatsby: ^2.13.52 => 2.13.52
gatsby-theme-docz: ^2.0.0-rc.1 => 2.0.0-rc.1
npmGlobalPackages:
gatsby-cli: 2.7.20

@dzuncoi
Copy link

dzuncoi commented Aug 7, 2019

I get this bug too, still cannot figure out how to fix it.

@raphaelfabeni
Copy link

The same here!

@lbucio
Copy link

lbucio commented Aug 11, 2019

Same here. Any luck on fixing this?

@bryanhidalgo
Copy link
Author

Seems like my problem was with my node version, I updated to the latest version (v12.8.0) and now is working for me.

@dusty
Copy link

dusty commented Aug 16, 2019

I'm getting the same problem. Upgrading node didn't fix it.

@dusty
Copy link

dusty commented Aug 17, 2019

I found this error went away when I removed gatsby-config.js which I was using to load the gatsby sass plugin.

module.exports = {
  plugins: ['gatsby-plugin-sass']
}

After that, I could never get any combination of loaders ('css-loader', 'postcss-loader', 'sass-loader',...) to work. I was getting all sorts of errors loading gatsby-docz-theme. (eg: "unknown word") as well as trying to load my scss files.

I finally ditched all that and just ran sass cli to transform my stylesheets and removed sass-loader from my webpack config. That worked and I finally got docz to build!!!


On a side-note it looked awful. It appears my bulma styles were conflicting with docz styles.
Show source was unreadable. But, this is all another issue. I've since gone back to docz 1.

Waiting patiently for some more releases - looking forward to the new version once its stable. :)

@rakannimer rakannimer added bug Something isn't working v2 labels Aug 27, 2019
@rakannimer
Copy link
Contributor

Could you please provide the rest of the command output ? There might be another clue there into what's happening

@rahulrmetocean
Copy link

rahulrmetocean commented Aug 30, 2019

Facing the same issue, the thing I have common with @dusty is that I tried adding a custom gatsby plugin in a file in /gatsby-config.js

module.exports = {
  plugins: [{ resolve: `gatsby-plugin-material-ui` }],
}

Docz ended up generating the following gatsby-config.js file in .docz folder with gatsby-config.custom.js having my plugin code


const { merge } = require('lodash/fp')

let custom
try {
  custom = require('./gatsby-config.custom')
} catch (err) {
  custom = {}
}

const config = {
  siteMetadata: {
    title: 'Some app',
    description: 'My awesome app using docz',
  },
  plugins: [
    {
      resolve: 'gatsby-theme-docz',
      options: {
        themeConfig: {},
        docgenConfig: {},
        menu: [],
        mdPlugins: [],
        hastPlugins: [],
        ignore: [],
        typescript: false,
        ts: false,
        propsParser: true,
        'props-parser': true,
        debug: false,
        native: false,
        openBrowser: false,
        o: false,
        open: false,
        'open-browser': false,
        root: 'C:\\Users\\rravindran\\metocean\\someapp\\.docz',
        base: '/',
        source: './',
        src: './',
        files: './src/**/*.mdx',
        public: '/public',
        dest: '.docz/dist',
        d: '.docz/dist',
        editBranch: 'master',
        eb: 'master',
        'edit-branch': 'master',
        config: '',
        title: 'Some app',
        description: 'My awesome app using docz',
        host: 'localhost',
        port: 3002,
        p: 3000,
        separator: '-',
        paths: {
          root: 'C:\\Users\\rravindran\\metocean\\someapp',
          templates:
            'C:\\Users\\rravindran\\metocean\\someapp\\node_modules\\docz-core\\dist\\templates',
          packageJson: 'C:\\Users\\rravindran\\metocean\\someapp\\package.json',
          docz: 'C:\\Users\\rravindran\\metocean\\someapp\\.docz',
          cache: 'C:\\Users\\rravindran\\metocean\\someapp\\.docz\\.cache',
          app: 'C:\\Users\\rravindran\\metocean\\someapp\\.docz\\app',
          appPublic: 'C:\\Users\\rravindran\\metocean\\someapp\\.docz\\public',
          appNodeModules:
            'C:\\Users\\rravindran\\metocean\\someapp\\node_modules',
          appPackageJson:
            'C:\\Users\\rravindran\\metocean\\someapp\\package.json',
          appYarnLock:
            'C:\\Users\\rravindran\\metocean\\someapp\\node_modules\\docz-core\\yarn.lock',
          ownNodeModules:
            'C:\\Users\\rravindran\\metocean\\someapp\\node_modules\\docz-core\\node_modules',
          gatsbyConfig:
            'C:\\Users\\rravindran\\metocean\\someapp\\gatsby-config.js',
          gatsbyBrowser:
            'C:\\Users\\rravindran\\metocean\\someapp\\gatsby-browser.js',
          gatsbyNode: 'C:\\Users\\rravindran\\metocean\\someapp\\gatsby-node.js',
          gatsbySSR: 'C:\\Users\\rravindran\\metocean\\someapp\\gatsby-ssr.js',
          importsJs:
            'C:\\Users\\rravindran\\metocean\\someapp\\.docz\\app\\imports.js',
          rootJs:
            'C:\\Users\\rravindran\\metocean\\someapp\\.docz\\app\\root.jsx',
          indexJs:
            'C:\\Users\\rravindran\\metocean\\someapp\\.docz\\app\\index.jsx',
          indexHtml:
            'C:\\Users\\rravindran\\metocean\\someapp\\.docz\\app\\index.html',
          db: 'C:\\Users\\rravindran\\metocean\\someapp\\.docz\\app\\db.json',
        },
      },
    },
  ],
}

module.exports = merge(config, custom)


I dont know much about lodash fp but the merge function apparently doesnt seem to merge array properties. It just overwrites the property value with the newest value
so

const merger = _.merge( {plugins:[{ id: 1 }]}, { plugins:[{ id:2 }]});
// returns {plugins: [{id:2}]} instead of both elements

Hence your plugin configuration for gatsby-theme-docz must be getting lost as soon as we add our own plugins as

module.exports = merge(config, custom)

@rakannimer
Copy link
Contributor

Hey @rahulrmetocean

I think you're right, yours and @dusty's problem are from a problem with merging the plugins field in the gatsby config files.

Going to open a separate issue to track that problem.

For future readers who encounter this, make sure to :

  1. update docz to latest version
  2. delete your node_modules folder
  3. delete the .docz folder
  4. yarn install && yarn docz dev
  5. If you still get the error, delete your yarn.lock file and go to step 2
  6. Still doesn't work ? Open an issue so we can help debug the problem.

@axe312ger
Copy link
Contributor

I still ran into this when having gatsby-theme-docz as dependency but not using it.

My setup does not render the docs on production, but in all other cases.

My workaround is to create the missing db docz entry. This at least let me build the website. It is not fixing the actual issue at all.

Thats my gatsby-node.js:

/**
 * This whole file is a workaround to prevent docz from failing when the
 * dependency is installed but gatsby-theme-docz is excluded in the gatsby-config.js
 *
 * Maybe related: https://github.com/doczjs/docz/issues/994
 */
const crypto = require('crypto')

const digest = (str) =>
  crypto
    .createHash('md5')
    .update(str)
    .digest('hex')

const isProduction = process.env.NODE_ENV === 'production'
const isStaging = !!process.env.STAGING

const renderDocs = isStaging || !isProduction

/**
 * If the docs are not rendered, create a fake db entry to prevent the parser for
 * useStaticQuery from failing via
 *
 *  ERROR #85901  GRAPHQL
 *
 *  There was an error in your GraphQL query:
 *
 *  Cannot query field "doczDb" on type "Query".
 *
 *  GraphQL request:3:9
 *  2 |       query {
 *  3 |         doczDb {
 *    |         ^
 *  4 |           id
 *
 *  File: node_modules/gatsby-theme-docz/src/hooks/useDbQuery.js:7:9
 */
exports.sourceNodes = ({ actions, createNodeId }, { forceDocs = false }) => {
  if (forceDocs || renderDocs) {
    console.log('skipping')
    return
  }

  console.log('faking docs db')

  const { createNode } = actions
  const db = JSON.stringify({})
  const contentDigest = digest(db)

  const node = {
    id: createNodeId('docz-db'),
    db,
    children: [],
    internal: {
      contentDigest,
      type: 'DoczDb',
    },
  }

  createNode(node)
}

@rakannimer
Copy link
Contributor

I still ran into this when having gatsby-theme-docz as dependency but not using it.

I'm sorry I'm not sure I understand what you mean by this. You've installed the dependency but didn't include as a gatsby plugin in your configuration ?

Any chance the project you're working on is open-source so I can take a look ?

@axe312ger
Copy link
Contributor

@rakannimer

You've installed the dependency but didn't include as a gatsby plugin in your configuration ?

Exactly. As docz adds dependencies and increases the bundle size even for pages outside of the / route, I don't include gatsby-theme-docz when building on my productio instance. On staging I have the docs generated for the team.

Any chance the project you're working on is open-source so I can take a look ?

Its very WIP and currently only works with the contentful starter. I am working on it currently on a daily basis and will polish both starters very soon.

https://github.com/axe312ger/gatsby-mdx-suite

@RichardBray
Copy link

For anyone still struggling with this issue, I fixed it on my end by replacing this line:

// doczrc.js
ignore: "README.md",

with this one:

// doczrc.js
ignore: ["README.md"],

@leggomuhgreggo
Copy link

For me, this resolved when I downgraded gatsby from 3.* to 2.*

Some of the gatsby-plugins docz uses had compatibility issues.

An alternative which might be worth exploring instead would be to install updated versions of the plugins.

Hope this helps. Love this effin tool.

@tiyunchen
Copy link

image
image

i spend a lot time to reslove this problem, first t think is my node or ts version promble, and i try many methods but it's not work, and finaly i find the promble is in the package.json repository field, i remove that field adn it's work, i dont now why????

@hellcoldby
Copy link

image
image

i spend a lot time to reslove this problem, first t think is my node or ts version promble, and i try many methods but it's not work, and finaly i find the promble is in the package.json repository field, i remove that field adn it's work, i dont now why????

@ tiyunchen
thank you for your reply to solve my problem

@renatobenks
Copy link
Member

@hellcoldby try to use the latest bumped version of docz (2.3.3-alpha.0) to see if it still happens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending-user-response v2
Projects
None yet
Development

No branches or pull requests