vite-plugin-graphql-loader weekly downloads statistics
By 0x31 · npm · Vite plugins
A Vite plugin for loading GraphQL files.
vite-plugin-graphql-loader has 122,924 recorded weekly downloads on npm, a decrease of 10.2% over the past 30 days, ranking #609 of 3,247 tracked listings.
About vite-plugin-graphql-loader
vite-plugin-graphql-loader
A Vite plugin for loading GraphQL .gql and .graphql files, based on graphql-tag/loader
Using Bun as well? bun-graphql-loader is the same loader behind Bun's plugin API, built from the same source in this repository.
This package doesn't generate TypeScript definitions from the queries and fragments - see vite-plugin-graphql-codegen if you require this.
Install
yarn add -D vite-plugin-graphql-loader graphql
or
npm i --save-dev vite-plugin-graphql-loader graphql
Compatibility
| Peer | Supported |
|---|---|
graphql | 16.x, 17.x |
vite | 5.x, 6.x, 7.x, 8.x |
| Node | ^20.19.0 || >=22.12.0 (GraphQL 17 itself requires Node 22+) |
Usage
In vite.config.ts or vite.config.js:
import { defineConfig } from "vite";
import graphqlLoader from "vite-plugin-graphql-loader";
export default defineConfig({
plugins: [graphqlLoader()],
});
Now you can import queries from .gql or .graphql files.
example.graphql:
#import "./ExampleImport.graphql"
fragment ExampleFragment on example {
id
name
}
query ExampleQuery {
example {
...ExampleFragment
...ExampleImport
}
}
example.js:
import ExampleQuery, { ExampleFragment } from "./example.graphql";
If you have multiple queries in the same file, import them like this:
import { FirstQuery, SecondQuery } from "./example.graphql";
TypeScript
If you are using TypeScript, you will have to declare .gql or .graphql files.
Create graphql.d.ts anywhere in your source directory:
declare module "*.gql";
declare module "*.graphql";
Alternatively, for full type information (replacing .gql with .graphql depending on what you use):
declare module "*.gql" {
const Query: import("graphql").DocumentNode;
export default Query;
export const _queries: Record<string, import("graphql").DocumentNode>;
export const _fragments: Record<string, import("graphql").DocumentNode>;
}
Every export is a DocumentNode. A fragment export is a document holding that fragment and the fragments it spreads, which is what gql interpolation and fragment composition expect.
import Document, { _queries, _fragments } from "./example.graphql";
console.log(Document); // Has type `DocumentNode`
console.log(_queries.ExampleQuery); // Has type `DocumentNode`
console.log(_fragments.ExampleFragment); // Has type `DocumentNode`
An operation whose name is a JavaScript reserved word has to be renamed on import:
import { delete as deleteThing } from "./things.graphql";
Changelog
v6.0.0:…
Description from the npm listing.
- graphql
- vite
- vite-plugin
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (170)Similar npm Vite plugins plugins
All 20 vite-plugin-graphql-loader alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/vite-plugin-graphql-loader. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.