Skip to content
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

Add documentation for mapping in gatsby-config #4054

Merged
merged 6 commits into from
Feb 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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