Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danielwaltz/vite-plugin-graphql-codegen
Zero-config vite plugin that uses the vite file watcher to run graphql codegen programmatically without needing to start a separate watcher
https://github.com/danielwaltz/vite-plugin-graphql-codegen
codegen graphql graphql-code-generator graphql-codegen plugin vite vite-plugin vite-plugin-graphql-codegen
Last synced: 6 days ago
JSON representation
Zero-config vite plugin that uses the vite file watcher to run graphql codegen programmatically without needing to start a separate watcher
- Host: GitHub
- URL: https://github.com/danielwaltz/vite-plugin-graphql-codegen
- Owner: danielwaltz
- License: mit
- Created: 2021-08-21T15:05:08.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-12-07T20:04:09.000Z (16 days ago)
- Last Synced: 2024-12-10T22:13:34.358Z (13 days ago)
- Topics: codegen, graphql, graphql-code-generator, graphql-codegen, plugin, vite, vite-plugin, vite-plugin-graphql-codegen
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/vite-plugin-graphql-codegen
- Size: 2.29 MB
- Stars: 83
- Watchers: 2
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Vite Plugin GraphQL Codegen
Zero-config vite plugin that uses the vite file watcher to run [graphql codegen](https://www.graphql-code-generator.com/) programmatically without needing to start a separate watcher.
## Setup GraphQL Codegen
Installation instructions found [here](https://www.graphql-code-generator.com/docs/getting-started/installation). Optional if already set up in project.
## Install Plugin
```bash
# npm
npm i -D vite-plugin-graphql-codegen# yarn
yarn add -D vite-plugin-graphql-codegen# pnpm
pnpm i -D vite-plugin-graphql-codegen
```## Initialize Plugin
```ts
// vite.config.tsimport { defineConfig } from 'vite';
import codegen from 'vite-plugin-graphql-codegen';export default defineConfig({
plugins: [
codegen(),
],
});
```## Options
Providing options is not required as sensible defaults are in place, but there may be times where it's helpful to disable codegen under certain circumstances, like when running builds in CI.
```ts
codegen({
/**
* Run codegen on server start.
*
* @default true
*/
runOnStart: boolean,
/**
* Run codegen on build. Will prevent build if codegen fails.
*
* @default true
*/
runOnBuild: boolean,
/**
* Enable codegen integration with vite file watcher.
*
* @default true
*/
enableWatcher: boolean,
/**
* Throw an error if codegen fails on server start.
*
* @default false
*/
throwOnStart: boolean,
/**
* Throw an error if codegen fails on build.
*
* @default true
*/
throwOnBuild: boolean,
/**
* Run codegen when a document matches.
*
* @default true
*/
matchOnDocuments: boolean,
/**
* Run codegen when a schema matches.
*
* @default false
*/
matchOnSchemas: boolean,
/**
* Manually define the codegen config.
*/
config: CodegenConfig,
/**
* Override parts of the codegen config just for this plugin.
*/
configOverride: Partial,
/**
* Override parts of the codegen config just for this plugin on server start.
*/
configOverrideOnStart: Partial,
/**
* Override parts of the codegen config just for this plugin on build.
*/
configOverrideOnBuild: Partial,
/**
* Override parts of the codegen config just for this plugin in the watcher.
*/
configOverrideWatcher: Partial,
/**
* Override the codegen config file path.
*/
configFilePathOverride: string,
/**
* Log various steps to aid in tracking down bugs.
*
* @default false
*/
debug: boolean,
});
```