@jeboehm/vite-plugin-graphql

1.0.3 • Public • Published

vite-plugin-graphql

Node.js CI

This plugin is used to import GraphQL queries.

Features

  • Import normalized queries as string type
  • Collect all used queries / mutation in the application and transmit only hashes to save bandwidth using persistent queries
  • Builds a persistent query hash map for use on server side
  • Automatically add __typename to requested types in queries

Getting started

Install the plugin:

npm install --save-dev @jeboehm/vite-plugin-graphql

Add the plugin to your vite.config.js:

import { defineConfig } from 'vite';
import VitePluginGraphQL from '@jeboehm/vite-plugin-graphql';

export default defineConfig(({mode}) => {
  return {
    plugins: [
        VitePluginGraphQL({
            hashMap: {
                enabled: mode === 'production',
                path: './queryHashMap.json',
            },
            queries: {
                usePersistentQuery: mode === 'production',
                addTypename: true,
            }
        }),
    ],
  };
});

Usage

// query is the default export
import {query, queryId} from './graphql/getUsers.graphql';

// query is either an object or string
console.log('Query:', query);
console.log('Query ID:', queryId);

Package Sidebar

Install

npm i @jeboehm/vite-plugin-graphql

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

670 kB

Total Files

10

Last publish

Collaborators

  • jeboehm