1.0.3 • Published 1 year ago

@jeboehm/vite-plugin-graphql v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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);