gatsby-plugin-graphql-tag-loader

Gatsby plugin for importing .graphql and .gql directly into js using graphql-tag/loader.

Install

$ yarn add gatsby-plugin-graphql-tag-loader

or

$ npm i --save gatsby-plugin-graphql-tag-loader

How to use

Simply add the plugin to your gatsby-config.js.

{
  plugins: [`gatsby-plugin-graphql-tag-loader`];
}

or use custom options

{
  plugins: [
    {
      resolve: `gatsby-plugin-graphql-tag-loader`,
      options: {
        exclude: /node_modules/, // default exclude value
        test: /\.(graphql|gql)$/, // default test value
      },
    },
  ];
}

Example

gatsby-config.js

{
  plugins: [`gatsby-plugin-graphql-tag-loader`];
}

currentUser.gql

query CurrentUserForLayout {
  currentUser {
    login
    avatar_url
  }
}

twoQueries.graphql

query MyQuery1 {
  ...
}

query MyQuery2 {
  ...
}

index.js

import currentUserQuery from "./currentUser.gql";
import { MyQuery1, MyQuery2 } from "./twoQueries.graphql";