onPostBootstrap: graphql is not a function #27638
-
DescriptionI would love to have access to the GraphQL server after the bootstrap is done, but it seems that the Steps to reproduceTo reproduce the issue, I am using the following snippet inside exports.onPostBootstrap = async ({ graphql, reporter }) => {
const pages = await graphql(
`
{
allSitePage {
nodes {
path
}
}
}
`
)
reporter.info(pages)
} Expected resultI should be able to retrieve the data from the query. Actual resultThe server throws an error saying: ERROR #11321 PLUGIN
"gatsby-node.js" threw an error while running the onPostBootstrap lifecycle:
graphql is not a function EnvironmentI set up a fresh project using gatsby-starter-blog. ➜ gatsby-starter-blog git:(master) ✗ gatsby info --clipboard
System:
OS: macOS 10.15.7
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.17.0 - ~/.nvm/versions/node/v12.17.0/bin/node
Yarn: 1.22.5 - /usr/local/bin/yarn
npm: 6.14.4 - ~/.nvm/versions/node/v12.17.0/bin/npm
Languages:
Python: 2.7.16 - /usr/bin/python
Browsers:
Chrome: 86.0.4240.111
Safari: 14.0
npmPackages:
gatsby: ^2.24.79 => 2.24.79
gatsby-image: ^2.4.21 => 2.4.21
gatsby-plugin-feed: ^2.5.14 => 2.5.14
gatsby-plugin-google-analytics: ^2.3.18 => 2.3.18
gatsby-plugin-manifest: ^2.4.34 => 2.4.34
gatsby-plugin-offline: ^3.2.33 => 3.2.33
gatsby-plugin-react-helmet: ^3.3.14 => 3.3.14
gatsby-plugin-sharp: ^2.6.42 => 2.6.42
gatsby-remark-copy-linked-files: ^2.3.19 => 2.3.19
gatsby-remark-images: ^3.3.35 => 3.3.35
gatsby-remark-prismjs: ^3.5.16 => 3.5.16
gatsby-remark-responsive-iframe: ^2.4.17 => 2.4.17
gatsby-remark-smartypants: ^2.3.13 => 2.3.13
gatsby-source-filesystem: ^2.3.34 => 2.3.34
gatsby-transformer-remark: ^2.8.41 => 2.8.41
gatsby-transformer-sharp: ^2.5.17 => 2.5.17
npmGlobalPackages:
gatsby-cli: 2.12.45 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Also, the official documentation doesn't provide any insight about how is supposed to be used or the parameters it receives 😞 |
Beta Was this translation helpful? Give feedback.
-
Hello! If you look at the TypeScript definitions and search for You'll want to use the |
Beta Was this translation helpful? Give feedback.
Hello!
If you look at the TypeScript definitions and search for
graphql<Tdata
you'll see that onlyCreatePagesArgs
andBuildArgs
receive that data in the arguments.You'll want to use the
onPostBuild
hook, e.g. the sitemap plugin is also doing that: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-sitemap/src/gatsby-node.js