vite-plugin-graphql-loader
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -38,3 +38,3 @@ "use strict"; | ||
const headerCode = ` | ||
const doc = ${JSON.stringify(documentNode)}; | ||
var doc = ${JSON.stringify(documentNode)}; | ||
doc.loc.source = ${JSON.stringify(documentNode.loc.source)}; | ||
@@ -52,3 +52,3 @@ `; | ||
outputCode += ` | ||
export default doc; | ||
module.exports = doc; | ||
`; | ||
@@ -71,3 +71,3 @@ } | ||
outputCode += ` | ||
export const ${opName} = oneQuery(doc, "${opName}"); | ||
module.exports["${opName}"] = oneQuery(doc, "${opName}"); | ||
`; | ||
@@ -74,0 +74,0 @@ } |
@@ -1,3 +0,3 @@ | ||
export declare const UNIQUE = "\nconst names = {};\nfunction unique(defs) {\n return defs.filter(\n function(def) {\n if (def.kind !== 'FragmentDefinition') return true;\n const name = def.name.value\n if (names[name]) {\n return false;\n } else {\n names[name] = true;\n return true;\n }\n }\n )\n}\n"; | ||
export declare const ONE_QUERY = "\n// Collect any fragment/type references from a node, adding them to the refs Set\nfunction collectFragmentReferences(node, refs) {\n if (node.kind === \"FragmentSpread\") {\n refs.add(node.name.value);\n } else if (node.kind === \"VariableDefinition\") {\n const type = node.type;\n if (type.kind === \"NamedType\") {\n refs.add(type.name.value);\n }\n }\n if (node.selectionSet) {\n node.selectionSet.selections.forEach(function(selection) {\n collectFragmentReferences(selection, refs);\n });\n }\n if (node.variableDefinitions) {\n node.variableDefinitions.forEach(function(def) {\n collectFragmentReferences(def, refs);\n });\n }\n if (node.definitions) {\n node.definitions.forEach(function(def) {\n collectFragmentReferences(def, refs);\n });\n }\n}\nconst definitionRefs = {};\n(function extractReferences() {\n doc.definitions.forEach(function(def) {\n if (def.name) {\n const refs = new Set();\n collectFragmentReferences(def, refs);\n definitionRefs[def.name.value] = refs;\n }\n });\n})();\nfunction findOperation(doc, name) {\n for (let i = 0; i < doc.definitions.length; i++) {\n const element = doc.definitions[i];\n if (element.name && element.name.value == name) {\n return element;\n }\n }\n}\nfunction oneQuery(doc, operationName) {\n // Copy the DocumentNode, but clear out the definitions\n const newDoc = {\n kind: doc.kind,\n definitions: [findOperation(doc, operationName)]\n };\n if (doc.hasOwnProperty(\"loc\")) {\n newDoc.loc = doc.loc;\n }\n // Now, for the operation we're running, find any fragments referenced by\n // it or the fragments it references\n const opRefs = definitionRefs[operationName] || new Set();\n const allRefs = new Set();\n let newRefs = new Set();\n // IE 11 doesn't support \"new Set(iterable)\", so we add the members of opRefs to newRefs one by one\n opRefs.forEach(function(refName) {\n newRefs.add(refName);\n });\n while (newRefs.size > 0) {\n const prevRefs = newRefs;\n newRefs = new Set();\n prevRefs.forEach(function(refName) {\n if (!allRefs.has(refName)) {\n allRefs.add(refName);\n const childRefs = definitionRefs[refName] || new Set();\n childRefs.forEach(function(childRef) {\n newRefs.add(childRef);\n });\n }\n });\n }\n allRefs.forEach(function(refName) {\n const op = findOperation(doc, refName);\n if (op) {\n newDoc.definitions.push(op);\n }\n });\n return newDoc;\n}\n\nexport default doc;\n"; | ||
export declare const UNIQUE = "\nvar names = {};\nfunction unique(defs) {\n return defs.filter(\n function(def) {\n if (def.kind !== 'FragmentDefinition') return true;\n var name = def.name.value\n if (names[name]) {\n return false;\n } else {\n names[name] = true;\n return true;\n }\n }\n )\n}\n"; | ||
export declare const ONE_QUERY = "\n// Collect any fragment/type references from a node, adding them to the refs Set\nfunction collectFragmentReferences(node, refs) {\n if (node.kind === \"FragmentSpread\") {\n refs.add(node.name.value);\n } else if (node.kind === \"VariableDefinition\") {\n var type = node.type;\n if (type.kind === \"NamedType\") {\n refs.add(type.name.value);\n }\n }\n if (node.selectionSet) {\n node.selectionSet.selections.forEach(function(selection) {\n collectFragmentReferences(selection, refs);\n });\n }\n if (node.variableDefinitions) {\n node.variableDefinitions.forEach(function(def) {\n collectFragmentReferences(def, refs);\n });\n }\n if (node.definitions) {\n node.definitions.forEach(function(def) {\n collectFragmentReferences(def, refs);\n });\n }\n}\nvar definitionRefs = {};\n(function extractReferences() {\n doc.definitions.forEach(function(def) {\n if (def.name) {\n var refs = new Set();\n collectFragmentReferences(def, refs);\n definitionRefs[def.name.value] = refs;\n }\n });\n})();\nfunction findOperation(doc, name) {\n for (var i = 0; i < doc.definitions.length; i++) {\n var element = doc.definitions[i];\n if (element.name && element.name.value == name) {\n return element;\n }\n }\n}\nfunction oneQuery(doc, operationName) {\n // Copy the DocumentNode, but clear out the definitions\n var newDoc = {\n kind: doc.kind,\n definitions: [findOperation(doc, operationName)]\n };\n if (doc.hasOwnProperty(\"loc\")) {\n newDoc.loc = doc.loc;\n }\n // Now, for the operation we're running, find any fragments referenced by\n // it or the fragments it references\n var opRefs = definitionRefs[operationName] || new Set();\n var allRefs = new Set();\n var newRefs = new Set();\n // IE 11 doesn't support \"new Set(iterable)\", so we add the members of opRefs to newRefs one by one\n opRefs.forEach(function(refName) {\n newRefs.add(refName);\n });\n while (newRefs.size > 0) {\n var prevRefs = newRefs;\n newRefs = new Set();\n prevRefs.forEach(function(refName) {\n if (!allRefs.has(refName)) {\n allRefs.add(refName);\n var childRefs = definitionRefs[refName] || new Set();\n childRefs.forEach(function(childRef) {\n newRefs.add(childRef);\n });\n }\n });\n }\n allRefs.forEach(function(refName) {\n var op = findOperation(doc, refName);\n if (op) {\n newDoc.definitions.push(op);\n }\n });\n return newDoc;\n}\n\nmodule.exports = doc;\n"; | ||
//# sourceMappingURL=snippets.d.ts.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
exports.UNIQUE = ` | ||
const names = {}; | ||
var names = {}; | ||
function unique(defs) { | ||
@@ -11,3 +11,3 @@ return defs.filter( | ||
if (def.kind !== 'FragmentDefinition') return true; | ||
const name = def.name.value | ||
var name = def.name.value | ||
if (names[name]) { | ||
@@ -29,3 +29,3 @@ return false; | ||
} else if (node.kind === "VariableDefinition") { | ||
const type = node.type; | ||
var type = node.type; | ||
if (type.kind === "NamedType") { | ||
@@ -51,7 +51,7 @@ refs.add(type.name.value); | ||
} | ||
const definitionRefs = {}; | ||
var definitionRefs = {}; | ||
(function extractReferences() { | ||
doc.definitions.forEach(function(def) { | ||
if (def.name) { | ||
const refs = new Set(); | ||
var refs = new Set(); | ||
collectFragmentReferences(def, refs); | ||
@@ -63,4 +63,4 @@ definitionRefs[def.name.value] = refs; | ||
function findOperation(doc, name) { | ||
for (let i = 0; i < doc.definitions.length; i++) { | ||
const element = doc.definitions[i]; | ||
for (var i = 0; i < doc.definitions.length; i++) { | ||
var element = doc.definitions[i]; | ||
if (element.name && element.name.value == name) { | ||
@@ -73,3 +73,3 @@ return element; | ||
// Copy the DocumentNode, but clear out the definitions | ||
const newDoc = { | ||
var newDoc = { | ||
kind: doc.kind, | ||
@@ -83,5 +83,5 @@ definitions: [findOperation(doc, operationName)] | ||
// it or the fragments it references | ||
const opRefs = definitionRefs[operationName] || new Set(); | ||
const allRefs = new Set(); | ||
let newRefs = new Set(); | ||
var opRefs = definitionRefs[operationName] || new Set(); | ||
var allRefs = new Set(); | ||
var newRefs = new Set(); | ||
// IE 11 doesn't support "new Set(iterable)", so we add the members of opRefs to newRefs one by one | ||
@@ -92,3 +92,3 @@ opRefs.forEach(function(refName) { | ||
while (newRefs.size > 0) { | ||
const prevRefs = newRefs; | ||
var prevRefs = newRefs; | ||
newRefs = new Set(); | ||
@@ -98,3 +98,3 @@ prevRefs.forEach(function(refName) { | ||
allRefs.add(refName); | ||
const childRefs = definitionRefs[refName] || new Set(); | ||
var childRefs = definitionRefs[refName] || new Set(); | ||
childRefs.forEach(function(childRef) { | ||
@@ -107,3 +107,3 @@ newRefs.add(childRef); | ||
allRefs.forEach(function(refName) { | ||
const op = findOperation(doc, refName); | ||
var op = findOperation(doc, refName); | ||
if (op) { | ||
@@ -116,4 +116,4 @@ newDoc.definitions.push(op); | ||
export default doc; | ||
module.exports = doc; | ||
`; | ||
//# sourceMappingURL=snippets.js.map |
{ | ||
"name": "vite-plugin-graphql-loader", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "A Vite plugin for loading GraphQL files.", | ||
@@ -12,4 +12,4 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"test": "vitest", | ||
"build": "rimraf ./dist && tsc", | ||
"test": "ts-node __test__/index.ts", | ||
"build": "rm -rf dist && tsc", | ||
"package:bump": "yarn version --patch", | ||
@@ -42,7 +42,6 @@ "package:publish": "yarn build && yarn package:bump && yarn publish" | ||
"glob": "^8.1.0", | ||
"rimraf": "^4.3.1", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.9.5", | ||
"vite": "^4.1.1", | ||
"vitest": "^0.28.5" | ||
"vite": "^4.1.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
6
14367