Skip to content

Commit

Permalink
Merge pull request #4619 from sielay/missing-mapping-doc
Browse files Browse the repository at this point in the history
Missing example of using mapping by ids
  • Loading branch information
m-allanson authored Mar 21, 2018
2 parents ae3624b + 138b0b9 commit 3a196b5
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions docs/docs/gatsby-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,91 @@ query BlogPost($slug: String!) {
}
```

Mapping can also be used to map an array of ids to any other collection of data. For example, if you have two JSON files
`experience.json` and `tech.json` as follows:

```javascript
// experience.json
[
{
"id": "companyA",
"company": "Company A",
"position": "Unicorn Developer",
"from": "Dec 2016",
"to": "Present",
"items": [
{
"label": "Responsibility",
"description": "Being an unicorn"
},
{
"label": "Hands on",
"tech": [
"REACT",
"NODE"
]
}
]
},
]
```

```javascript
// tech.json
[
{
"id": "REACT",
"icon": "facebook",
"color": "teal",
"label": "React"
},
{
"id": "NODE",
"icon": "server",
"color": "green",
"label": "NodeJS"
}
]
```

And then add the following rule to your `gatsby-config.js`:

```javascript
module.exports = {
plugins: [...],
mapping: {
'ExperienceJson.items.tech': `TechJson`
},
}
```

You can query the `tech` object via the referred ids in `experience`:

```graphql
query CV {
experience: allExperienceJson {
edges {
node {
company
position
from
to
items {
label
description
link
tech {
label
color
icon
}
}
}
}
}
}
```

## Proxy

Setting the proxy config option will tell the development server to proxy any unknown requests to your specified server. For example:
Expand Down

0 comments on commit 3a196b5

Please sign in to comment.