I have a v2 Site running which gets sources from the filesystem via gatsby-source-filesystem. Now I wanted to add DatoCMS as a source. As soon as I add the plugin, the queries in gatsby-node.js for content from the filesystem won't work anymore.
error gatsby-node.js returned an error
error Cannot read property 'allmycontent' of undefined
System:
OS: macOS High Sierra 10.13.5
CPU: x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Shell: 5.3 - /bin/zsh
Binaries:
Node: 8.11.3 - ~/.nvm/versions/node/v8.11.3/bin/node
Yarn: 1.7.0 - /usr/local/bin/yarn
npm: 5.6.0 - ~/.nvm/versions/node/v8.11.3/bin/npm
Browsers:
Chrome: 67.0.3396.99
Firefox: 60.0.2
Safari: 11.1.1
npmPackages:
gatsby: next => 2.0.0-beta.17
gatsby-image: next => 2.0.0-beta.4
gatsby-plugin-google-analytics: next => 2.0.0-beta.2
gatsby-plugin-netlify: next => 2.0.0-beta.2
gatsby-plugin-react-helmet: next => 3.0.0-beta.3
gatsby-plugin-sharp: next => 2.0.0-beta.2
gatsby-plugin-sitemap: next => 2.0.0-beta.2
gatsby-plugin-styled-components: next => 3.0.0-beta.2
gatsby-plugin-typography: next => 2.2.0-beta.2
gatsby-source-datocms: next => 2.0.0-alpha.1
gatsby-source-filesystem: next => 2.0.1-beta.3
gatsby-transformer-excel: next => 2.1.1-beta.2
gatsby-transformer-json: next => 2.1.1-beta.2
gatsby-transformer-remark: next => 2.1.1-beta.2
gatsby-transformer-sharp: next => 2.1.1-beta.3
npmGlobalPackages:
gatsby-cli: 1.1.58
I created a sample repository of the problem: https://github.com/pgegenfurtner/gatsby-sources-error
Thanks for the demo repo, that's very helpful.
When running gatsby develop, the error I saw was:
success building schema — 3.967 s
⠁ Your site's "gatsby-node.js" must set the page path when creating a page
Your one markdown file contains the right info for doing this... Digging around in http://localhost:8000/___graphql, it turns out that the DatoCMS plugin is creating markdown nodes from your content, which gets picked up by your allMarkdownRemark { ... query.
Query:
{
allMarkdownRemark {
edges {
node {
internal {
content
type
contentDigest
owner
}
parent {
id
__typename
}
html
}
}
}
}
Result:
{
"data": {
"allMarkdownRemark": {
"edges": [
{
"node": {
"internal": {
"content": "\nLa la la",
"type": "MarkdownRemark",
"contentDigest": "aad1246121405da978eedabcf64ee448",
"owner": "gatsby-transformer-remark"
},
"parent": {
"id": "bde3ec30-c7b5-5487-967e-5eb649ba5305",
"__typename": "File"
},
"html": "<p>La la la</p>"
}
},
{
"node": {
"internal": {
"content": "Some Content",
"type": "MarkdownRemark",
"contentDigest": "eec0571c9b441cf8cd567b2fe9a7fbe0",
"owner": "gatsby-transformer-remark"
},
"parent": {
"id": "DatoCmsTest-333029-enContentTextNode",
"__typename": "DatoCmsTestContentTextNode"
},
"html": "<p>Some Content</p>"
}
}
]
}
}
}
There are two results, instead of the one result we're expecting. The second result coming from DatoCMS.
You can adjust your query with a filter, to include only markdown nodes that match a filepath regex:
allMarkdownRemark(
filter: {fileAbsolutePath: {regex: "/pages/"}}
) {
// ...your query here
Gatsby's GraphQL Reference docs have more info on the functions GraphQL can apply to your results.
Ohhhhhhh, I see. Didn't think about the markdown transformer picking up content from DatoCMS. I expected the error to come from another point (the filesystem plugin).
To query-around a bit in graphiql is a very good hint for future debugging of problems.
Now it's clear, thank you very much!
Most helpful comment
Ohhhhhhh, I see. Didn't think about the markdown transformer picking up content from DatoCMS. I expected the error to come from another point (the filesystem plugin).
To query-around a bit in graphiql is a very good hint for future debugging of problems.
Now it's clear, thank you very much!