Migrate to Netlify Today

Netlify announces the next evolution of Gatsby Cloud. Learn more

ContactSign Up
Community Plugin
View plugin on GitHub

gatsby-yaml-full-import npm

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
  }
}

License

The MIT License

© 2023 Gatsby, Inc.