JSPM

gatsby-source-graphql

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 20539
  • Score
    100M100P100Q143768F
  • License MIT

A Gatsby source plugin for pulling in data from GraphQL APIs.

Package Exports

  • gatsby-source-graphql
  • gatsby-source-graphql/gatsby-node

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gatsby-source-graphql) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

gatsby-source-graphql

Build Status npm Codecov.io

A Gatsby source plugin for pulling in data from GraphQL APIs.

Installation

Yarn

$ yarn add --dev gatsby-source-graphql

npm

$ npm install --save-dev gatsby-source-graphql

Usage

With gatsby-source-filesystem

// gatsby-config.js

// Optionally pull in environment variables
require('dotenv').config({
  path: `.env.${process.env.NODE_ENV}`,
});

module.exports = {
  // ...
  plugins: [
    {
      resolve: 'gatsby-source-filesystem',
      options: {
        name: 'queries',
        path: `${__dirname}/src/queries/`,
      },
    },
    {
      resolve: 'gatsby-source-graphql',
      options: {
        headers: {
          authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
        },
        url: 'https://api.github.com/graphql',
      },
    },
  ]
}
# src/queries/github.graphql
{
  viewer {
    name
    url
  }
}

How to query

Given the above example with a GraphQL file named github.graphql, you would query Gatsby like so:

query GitHubViewerQuery {
  githubGraphQl {
    viewer {
      name
      url
    }
  }
}

Change Log

Full Change Log

v1.1.0 (2018-06-05)

  • [67d99754ad] - Allow a promise for asynchronously loading options (#4) (Judah Anthony)
  • [4471e2c221] - Improve usage instructions (#3) (Tomasz Radziejewski)

License

MIT © Neil Kistner