gatsby-yaml-full-import
v5.0.0
Published
Import other YAML files or fields using !import tag
Downloads
18
Readme
gatsby-yaml-full-import
Plugin for gatsby-transformer-yaml-full
to enable import of other YAML files
or fields using !import
tag.
Installation
npm install gatsby-yaml-full-import gatsby-transformer-yaml-full
Usage
/* gatsby-config.js */
module.exports = {
plugins: [
{
resolve: 'gatsby-transformer-yaml-full',
options: {
plugins: ['gatsby-yaml-full-import']
}
}
]
}
Import all fields from a file
The following ./index.yaml
and ./post.yaml
files, respectively:
---
importedPost: !import ./post.yaml
title: Post title
Will return:
{
data: {
indexYaml: {
importedPost: {
title: 'Post title'
}
}
}
}
With the following query:
query {
indexYaml {
importedPost {
title
}
}
}
Import a specific field from a file
An exclamation mark (!
) separates the file name from the field query. The
field query supports array indexes too.
The following ./index.yaml
and ./post.yaml
files, respectively:
---
importedAuthorName: !import ./post.yaml!authors.1.name
authors:
- name: John Doe
- name: John Q.
Will return:
{
data: {
indexYaml: {
importedAuthorName: 'John Q.'
}
}
}
With the following query:
query {
indexYaml {
importedAuthorName
}
}