Skip to content

Commit

Permalink
Add documentation for mapping in gatsby-config (#4054)
Browse files Browse the repository at this point in the history
* Add documentation for mapping

* Fix glitch in pasted code

* Update gatsby-config.md

* format

* Update gatsby-config.md

* Update gatsby-config.md
  • Loading branch information
ajayns authored and KyleAMathews committed Feb 16, 2018
1 parent 3a713ad commit d520be2
Showing 1 changed file with 57 additions and 5 deletions.
62 changes: 57 additions & 5 deletions docs/docs/gatsby-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ This way you can store it in one place, and pull it whenever you need it. If you

See a fuller description and sample usage in [Gatsby.js Tutorial Part Four](/tutorial/part-four/#data-in-gatsby).

## plugins
## Plugins

Plugins are Node.js packages that implement Gatsby APIs. The config file accepts an array of plugins. Some plugins may need only to be listed by name, while others may take options (see the docs for individual plugins).

Expand Down Expand Up @@ -69,7 +69,7 @@ module.exports = {

See more about [Adding a Path Prefix](/docs/path-prefix/).

## polyfill
## Polyfill

Gatsby uses the ES6 Promise API. Because some browsers don't support this, Gatsby includes a Promise polyfill by default.

Expand All @@ -83,11 +83,63 @@ module.exports = {

See more about [Browser Support](/docs/browser-support/#polyfills) in Gatsby.

## mapping
## Mapping node types

TODO
Gatsby includes an advanced feature that lets you create "mappings" between node types.

## proxy
For instance, imagine you have a multi-author markdown blog where you want to "link" from each blog post to the author information stored in a yaml file named `author.yaml`:

```markdown
---
title: A blog post
author: Kyle Mathews
---

A treatsie on the efficacy of bezoar for treating agricultural pesticide poisoning.
```

author.yaml

```yaml
- id: Kyle Mathews
bio: Founder @ GatsbyJS. Likes tech, reading/writing, founding things. Blogs at bricolage.io.
twitter: "@kylemathews"
```
You can map between the `author` field in `frontmatter` to the id in the `author.yaml` objects by adding to your `gatsby-config.js`:

```javascript
module.exports = {
plugins: [...],
mapping: {
"MarkdownRemark.frontmatter.author": `AuthorYaml`,
},
}
```

Gatsby then uses this mapping when creating the GraphQL schema to enable you to query data from both sources:

```graphql
query BlogPost($slug: String!) {
markdownRemark(fields: { slug: { eq: $slug } }) {
html
fields {
slug
}
frontmatter {
title
author {
# This now links to the author object
id
bio
twitter
}
}
}
}
```

## 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 d520be2

Please sign in to comment.