vite-plugin-graphql-loader
Advanced tools
Comparing version 2.0.0 to 3.0.0
@@ -0,1 +1,3 @@ | ||
declare module "*.graphql"; | ||
declare module "*.gql"; | ||
export declare const vitePluginGraphqlLoader: () => { | ||
@@ -2,0 +4,0 @@ name: string; |
@@ -1,13 +0,7 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.vitePluginGraphqlLoader = void 0; | ||
const os_1 = __importDefault(require("os")); | ||
const graphql_tag_1 = __importDefault(require("graphql-tag")); | ||
const snippets_1 = require("./snippets"); | ||
import { EOL } from "os"; | ||
import { gql } from "graphql-tag"; | ||
import { ONE_QUERY, UNIQUE } from "./snippets.js"; | ||
const expandImports = (source) => { | ||
const lines = source.split(/\r\n|\r|\n/); | ||
let outputCode = snippets_1.UNIQUE; | ||
let outputCode = UNIQUE; | ||
lines.some((line) => { | ||
@@ -19,3 +13,3 @@ const result = line.match(/^#\s?import (.+)$/); | ||
const appendDefinition = `doc.definitions = doc.definitions.concat(unique(${parseDocument}.definitions));`; | ||
outputCode += appendDefinition + os_1.default.EOL; | ||
outputCode += appendDefinition + EOL; | ||
} | ||
@@ -26,3 +20,3 @@ return line.length > 0 && line[0] !== "#"; | ||
}; | ||
const vitePluginGraphqlLoader = () => { | ||
export const vitePluginGraphqlLoader = () => { | ||
const graphqlRegex = /\.(?:gql|graphql)$/; | ||
@@ -36,3 +30,3 @@ return { | ||
} | ||
const documentNode = (0, graphql_tag_1.default) ` | ||
const documentNode = gql ` | ||
${source} | ||
@@ -58,3 +52,3 @@ `; | ||
else { | ||
outputCode += snippets_1.ONE_QUERY; | ||
outputCode += ONE_QUERY; | ||
for (const op of documentNode.definitions) { | ||
@@ -79,8 +73,3 @@ if (op.kind === "OperationDefinition" || | ||
const importOutputCode = expandImports(source); | ||
const allCode = headerCode + | ||
os_1.default.EOL + | ||
importOutputCode + | ||
os_1.default.EOL + | ||
outputCode + | ||
os_1.default.EOL; | ||
const allCode = headerCode + EOL + importOutputCode + EOL + outputCode + EOL; | ||
return allCode; | ||
@@ -90,4 +79,3 @@ }, | ||
}; | ||
exports.vitePluginGraphqlLoader = vitePluginGraphqlLoader; | ||
exports.default = exports.vitePluginGraphqlLoader; | ||
export default vitePluginGraphqlLoader; | ||
//# sourceMappingURL=index.js.map |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ONE_QUERY = exports.UNIQUE = void 0; | ||
exports.UNIQUE = ` | ||
export const UNIQUE = ` | ||
const names = {}; | ||
@@ -21,3 +18,3 @@ function unique(defs) { | ||
`; | ||
exports.ONE_QUERY = ` | ||
export const ONE_QUERY = ` | ||
// Collect any fragment/type references from a node, adding them to the refs Set | ||
@@ -24,0 +21,0 @@ function collectFragmentReferences(node, refs) { |
{ | ||
"name": "vite-plugin-graphql-loader", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "A Vite plugin for loading GraphQL files.", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
@@ -15,3 +16,4 @@ "types": "dist/index.d.ts", | ||
"package:bump": "yarn version --patch", | ||
"package:publish": "yarn build && yarn package:bump && yarn publish" | ||
"package:publish": "yarn build && yarn package:bump && yarn publish", | ||
"lint": "yarn prettier -w src tests/**/*.ts && yarn eslint --fix" | ||
}, | ||
@@ -35,14 +37,18 @@ "repository": { | ||
"dependencies": { | ||
"graphql": "^16.6.0", | ||
"graphql": "^16.8.1", | ||
"graphql-tag": "^2.12.6" | ||
}, | ||
"devDependencies": { | ||
"@types/glob": "^8.0.1", | ||
"@types/node": "^16", | ||
"glob": "^8.1.0", | ||
"rimraf": "^4.3.1", | ||
"typescript": "^4.9.5", | ||
"vite": "^4.1.1", | ||
"vitest": "^0.28.5" | ||
"@types/node": "^20", | ||
"eslint": "^8.56.0", | ||
"glob": "^10.3.10", | ||
"prettier": "^3.2.4", | ||
"rimraf": "^5.0.5", | ||
"typescript": "^5.3.3", | ||
"vite": "^5.0.12", | ||
"vitest": "^1.2.1" | ||
}, | ||
"prettier": { | ||
"tabWidth": 4 | ||
} | ||
} |
@@ -9,2 +9,4 @@ # vite-plugin-graphql-loader | ||
If you are using TypeScript, I recommend using GraphQL Codegen and [vite-plugin-graphql-codegen](https://www.npmjs.com/package/vite-plugin-graphql-codegen) instead to generate TypesScript interfaces for your queries and fragments. | ||
## Install | ||
@@ -64,2 +66,3 @@ | ||
declare module "*.gql"; | ||
declare module "*.graphql"; | ||
@@ -72,1 +75,5 @@ // Or if you aren't using fragments: | ||
``` | ||
## Changelog | ||
**_v3.0.0_**: Moved from CJS to ESM, inline with Vite 5.0's CJS deprecation. If you are using CommonJS, continue using v2.0 of this package. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
15212
77
Yes
8
196
Updatedgraphql@^16.8.1