-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Mapping for two JSONs #4596
Comments
Also I just realised that after clearing cache graphql isn't very happy with approach made in |
Did you miss comma after first mapping entry and in your This does work - using exact same json files and same mapping (after adding missing commas). |
I edited that manually to give more abstract example. Let me check and come back to you. So for JSON |
Ok. Did not manage that to work, so (again sorry for silly question) could you please take a look experience.json [
{
"id": "A",
"company": "A",
"items": [
{
"label": "Hands on",
"tech": [
"JAVASCRIPT",
"TYPESCRIPT",
"ELECTRON",
"REACT",
"ANGULAR",
"DOCKER",
"NODE",
"AWS"
]
}
]
}
] tech.json [
{
"id": "JAVASCRIPT",
"icon": "html5",
"color": "yellow",
"label": "JavaScript"
},
{
"id": "TYPESCRIPT",
"icon": "html5",
"color": "blue",
"label": "TypeScript"
},
{
"id": "ELECTRON",
"icon": "desktop",
"color": "olive",
"label": "Electron"
},
{
"id": "REACT",
"icon": "facebook",
"color": "teal",
"label": "React"
},
{
"id": "ANGULAR",
"icon": "google",
"color": "red",
"label": "Angular"
},
{
"id": "DOCKER",
"icon": "server",
"color": "teal",
"label": "Docker"
},
{
"id": "NODE",
"icon": "server",
"color": "green",
"label": "NodeJS"
},
{
"id": "ANSIBLE",
"icon": "server",
"color": "black",
"label": "Ansible"
},
{
"id": "MONGO",
"icon": "database",
"color": "green",
"label": "Mongo"
},
{
"id": "AWS",
"icon": "amazon",
"color": "yellow",
"label": "AWS"
},
{
"id": "PHP",
"icon": "server",
"color": "blue",
"label": "PHP"
},
{
"id": "SYMFONY",
"icon": "server",
"color": "green",
"label": "Symfony"
},
{
"id": "ACTIONSCRIPT",
"icon": "file pdf outline",
"color": "red",
"label": "ActionScript/Flash"
},
{
"id": "MYSQL",
"icon": "database",
"color": "teal",
"label": "MySQL"
},
{
"id": "VB",
"icon": "microsoft edge",
"color": "teal",
"label": "VisualBasic"
}
] Mapping in
Trick with exports.sourceNodes = ({boundActionCreators, getNodes, getNode}) => {
const {createNodeField} = boundActionCreators;
const booksOfAuthors = {};
// Iterate thorugh all markdown nodes to link books to author
// and build author index
const markdownNodes = getNodes()
.filter(node => node.internal.type === `ExperienceJson`)
.forEach(node => {
node.items.forEach(item => {
if (item.tech) {
item.tech = item.tech.map(id => {
if (typeof id === 'string') {
return getNodes().find(
node2 =>
node2.internal.type === `TechJson` &&
node2.id === id
);
}
return id;
});
}
});
});
}; Thanks for advice @pieh |
If you remove your custom mapping from |
Thank you @pieh. Maybe worth adding such example to mapping doc? Should I do PR later? |
I think it would be worth adding to docs for two reasons:
Your PR surely would be welcome! 👍 |
Turned out that it did not work for me for different reason. Made PR to expose errors #4618 with more detail. |
Description
Mapping feature is nicely explained on example of FrontMatter, but not clear when it comes to combining two YAMLs or JSONs.
Steps to reproduce
I have two JSONs
I can create
join
behaviour to use with GraphQL by editinggatsby-node.js
as below, but can't figure out how to do it using mapping ingatsby-config.js
Expected result
If I understand mapping, I should be able to do something like
Actual result
Can't figure it out
Environment
npm list gatsby
): 1.9.100gatsby --version
): 1.1.45File contents (if changed):
gatsby-config.js
: n/apackage.json
: n/agatsby-node.js
: n/agatsby-browser.js
: n/agatsby-ssr.js
: n/aThe text was updated successfully, but these errors were encountered: