Closed abooayoob closed 5 years ago
@abooayoob can you create a reproduction and also is gatsby-source-kontohjelp-category
a local plugin you're working on?
@jonniebigodes yup, thanks, will try to set up a repro. Yeah, gatsby-source-kontohjelp-category
is a local source plugin that calls an internal api where I work. Will cook up something similar.
@jonniebigodes Here is the reproduction repo. If you clone, npm install
and then try to run with start
, you will see similar output, only less.
The problem is that I am creating a page and putting an object in the context field which causes the output. There is no graphql involved actually.
In my original project I am creating many pages, with many of these large and weird objects (created by the xml2js) package.
@abooayoob i've been looking at the code you supplied and i think i have a solution for your issue. Going to enumerate the steps i took.
gatsby develop
and i was able to confirm the issue at hand.data.js
which is nothing more than, nothing else than the json you get from your internal api.data_v1.json
renaming alll $
elements into attributes
and all _
elements into content
.So what was previously :
exports.data = {
txt: {
"#name": "txt",
children: [
{
$: {
topic_id: "{6B30A50D-87BB-4E5A-8DAE-E24304BB287F}",
bm: "-670606198",
source: "_kontohjelp",
},
"#name": "div",
children: [
{
$: { id: "-670606198" },
"#name": "section",
children: [
{
_: "Skattefri dekning av kontingent til serviceorganisasjoner",
"#name": "h1",
children: [
{
"#name": "__text__",
_:
"Skattefri dekning av kontingent til serviceorganisasjoner",
},
],
},
.....
is now:
{
"txt": {
"#name": "txt",
"children": [
{
"attributes": {
"topic_id": "{6B30A50D-87BB-4E5A-8DAE-E24304BB287F}",
"bm": "-670606198",
"source": "_kontohjelp"
},
"#name": "div",
"children": [
{
"attributes": {
"id": "-670606198"
},
"#name": "section",
"children": [
{
"content": "Skattefri dekning av kontingent til serviceorganisasjoner",
"#name": "h1",
"children": [
{
"#name": "__text__",
"content": "Skattefri dekning av kontingent til serviceorganisasjoner"
}
]
},
Modified gatsby-node.js
to the following:
exports.createPages = ({ actions }) => {
const { createPage } = actions
const jsonContent= require('./data_v1.json')
createPage({
path: "/bam/",
component: require.resolve('./src/templates/kontohjelp.js'),
context: {
data:jsonContent
},
})
}
- To keep it separated created a template called `kontohjelp.js` inside `./src/templates/` with the following code:
```javascript
import React from 'react';
const Kontohjelp=({pageContext})=>{
console.log('====================================');
console.log(`props:${JSON.stringify(pageContext,null,2)}`);
console.log('====================================');
return (
<div>
<h3>this is Kontohjelp</h3>
</div>
)
}
export default Kontohjelp
gatsby develop
and it yelded the following:Opening up http:/localhost:8000/bam
yelds the following:
Stopped Gatsby and issued gatsby clean
and gatsby build && gatsby serve
to clean the .cache
and public
folders and issue a production build and mock it, as i've opened another browser window http:/localhost:9000/bam
yelded the same result as above.
Based on the documentation for the package in question and i haven't fully tested it yet, but it could exist a option that takes care of part of the issue at hand, the other part you will probably need to do some extra work on the json itself.
Feel free to provide feedback so that we can close this issue or continue to work on it till we find a solution.
@jonniebigodes Thanks a bunch, this fixes the warnings and issue that I was facing!
Although, I don't think it is clear or intuitive why just renaming some fields from $
and _
is the solution to this issue.
I think we can close this issue. But I think there is either a bug or something that needs to be documentet so that others don't encounter the same problem. I can look into it this or next week. Unless someone else want's to have a go at it.
@abooayoob it could be a dependency of gatsby acting up or something in that nature that generates this sort of issue. If you want feel free to check on it and see if you find something and with that document the issue and the fix for it. 👍
Summary
When i run
gatsby develop
orgatsby build
I get an infinite loop of warnings similar to this:outputs lines like theese:
warn Multiple node fields resolve to the same GraphQL field `SitePage.context.contentList.js.children.section.div.table.tbody.tr.td.p.span._` - [`_`, `$`]. Gatsby will use `_`.
Only way to get out is close vs code but site does not get built.
I am not sure why this happens, any ideas?
Relevant information
If I comment out theese lines, causing the warning, in gatsby, then I don't get the warnings and the site gets built and works fine.
In case you don't need/want to follow the link above right now:
gatsby/packages/gatsby/src/schema/infer/add-inferred-fields.js
lines72 - 78
:Environment (if relevant)
System: OS: macOS 10.14.2 CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz Shell: 3.2.57 - /bin/bash Binaries: Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node npm: 6.4.1 - ~/.nvm/versions/node/v10.15.3/bin/npm Languages: Python: 2.7.10 - /usr/bin/python Browsers: Chrome: 74.0.3729.169 Safari: 12.0.2 npmPackages: gatsby: ^2.6.0 => 2.6.0 gatsby-image: ^2.1.0 => 2.1.0 gatsby-plugin-jss: ^2.0.9 => 2.0.9 gatsby-plugin-manifest: ^2.1.1 => 2.1.1 gatsby-plugin-offline: ^2.1.1 => 2.1.1 gatsby-plugin-react-helmet: ^3.0.12 => 3.0.12 gatsby-plugin-sharp: ^2.0.37 => 2.0.37 gatsby-source-filesystem: ^2.0.37 => 2.0.37 gatsby-transformer-sharp: ^2.1.19 => 2.1.19
File contents (if changed)
gatsby-config.js
:package.json
:gatsby-node.js
:gatsby-browser.js
:gatsby-ssr.js
: