graphql-mini-transforms
Advanced tools
Comparing version 3.0.2 to 3.1.0
@@ -11,29 +11,32 @@ 'use strict'; | ||
const THIS_FILE = fsExtra.readFileSync(__filename); | ||
const getCacheKey = function getCacheKey(fileData, filename) { | ||
return crypto.createHash('md5').update(THIS_FILE).update(fileData).update(filename).digest('hex'); | ||
}; | ||
const process = function process(rawSource) { | ||
const { | ||
imports, | ||
source | ||
} = document.extractImports(rawSource); | ||
const utilityImports = ` | ||
var {print, parse} = require('graphql'); | ||
var {cleanDocument, toSimpleDocument} = require(${JSON.stringify(`${__dirname}/document.js`)}); | ||
`; | ||
const importSource = imports.map((imported, index) => `var importedDocument${index} = require(${JSON.stringify(imported)});`).join('\n'); | ||
const appendDefinitionsSource = imports.map((_, index) => `document.definitions.push.apply(document.definitions, parse(importedDocument${index}.source).definitions);`).join('\n'); | ||
return ` | ||
${utilityImports} | ||
${importSource} | ||
const transformer = { | ||
getCacheKey(fileData, filename) { | ||
return crypto.createHash('md5').update(THIS_FILE).update(fileData).update(filename).digest('hex'); | ||
}, | ||
var document = ${JSON.stringify(graphql.parse(source))}; | ||
process(rawSource) { | ||
const { | ||
imports, | ||
source | ||
} = document.extractImports(rawSource); | ||
const utilityImports = ` | ||
var {print, parse} = require('graphql'); | ||
var {cleanDocument, toSimpleDocument} = require(${JSON.stringify(`${__dirname}/document.js`)}); | ||
`; | ||
const importSource = imports.map((imported, index) => `var importedDocument${index} = require(${JSON.stringify(imported)});`).join('\n'); | ||
const appendDefinitionsSource = imports.map((_, index) => `document.definitions.push.apply(document.definitions, parse(importedDocument${index}.source).definitions);`).join('\n'); | ||
return ` | ||
${utilityImports} | ||
${importSource} | ||
${appendDefinitionsSource} | ||
var document = ${JSON.stringify(graphql.parse(source))}; | ||
module.exports = toSimpleDocument(cleanDocument(document, {removeUnused: false})); | ||
`; | ||
${appendDefinitionsSource} | ||
module.exports = toSimpleDocument(cleanDocument(document, {removeUnused: false})); | ||
`; | ||
} | ||
}; | ||
exports.getCacheKey = getCacheKey; | ||
exports.process = process; | ||
exports.default = transformer; |
@@ -11,29 +11,32 @@ 'use strict'; | ||
const THIS_FILE = fsExtra.readFileSync(__filename); | ||
const getCacheKey = function getCacheKey(fileData, filename) { | ||
return crypto.createHash('md5').update(THIS_FILE).update(fileData).update(filename).digest('hex'); | ||
}; | ||
const process = function process(rawSource) { | ||
const { | ||
imports, | ||
source | ||
} = document.extractImports(rawSource); | ||
const utilityImports = ` | ||
var {print} = require('graphql'); | ||
var {cleanDocument} = require(${JSON.stringify(`${__dirname}/document.js`)}); | ||
`; | ||
const importSource = imports.map((imported, index) => `var importedDocument${index} = require(${JSON.stringify(imported)});`).join('\n'); | ||
const appendDefinitionsSource = imports.map((_, index) => `document.definitions.push.apply(document.definitions, importedDocument${index}.definitions);`).join('\n'); | ||
return ` | ||
${utilityImports} | ||
${importSource} | ||
const transformer = { | ||
getCacheKey(fileData, filename) { | ||
return crypto.createHash('md5').update(THIS_FILE).update(fileData).update(filename).digest('hex'); | ||
}, | ||
var document = ${JSON.stringify(graphql.parse(source))}; | ||
process(rawSource) { | ||
const { | ||
imports, | ||
source | ||
} = document.extractImports(rawSource); | ||
const utilityImports = ` | ||
var {print} = require('graphql'); | ||
var {cleanDocument} = require(${JSON.stringify(`${__dirname}/document.js`)}); | ||
`; | ||
const importSource = imports.map((imported, index) => `var importedDocument${index} = require(${JSON.stringify(imported)});`).join('\n'); | ||
const appendDefinitionsSource = imports.map((_, index) => `document.definitions.push.apply(document.definitions, importedDocument${index}.definitions);`).join('\n'); | ||
return ` | ||
${utilityImports} | ||
${importSource} | ||
${appendDefinitionsSource} | ||
var document = ${JSON.stringify(graphql.parse(source))}; | ||
module.exports = cleanDocument(document, {removeUnused: false}); | ||
`; | ||
${appendDefinitionsSource} | ||
module.exports = cleanDocument(document, {removeUnused: false}); | ||
`; | ||
} | ||
}; | ||
exports.getCacheKey = getCacheKey; | ||
exports.process = process; | ||
exports.default = transformer; |
@@ -44,12 +44,10 @@ import { createHash } from 'crypto'; | ||
export function toSimpleDocument(document) { | ||
var _a, _b; | ||
return { | ||
id: document.id, | ||
name: operationNameForDocument(document), | ||
source: (_b = (_a = document.loc) === null || _a === void 0 ? void 0 : _a.source) === null || _b === void 0 ? void 0 : _b.body, | ||
source: document.loc?.source?.body, | ||
}; | ||
} | ||
function operationNameForDocument(document) { | ||
var _a, _b; | ||
return (_b = (_a = document.definitions.find((definition) => definition.kind === 'OperationDefinition')) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.value; | ||
return document.definitions.find((definition) => definition.kind === 'OperationDefinition')?.name?.value; | ||
} | ||
@@ -150,3 +148,3 @@ function removeUnusedDefinitions(document) { | ||
function stripDocumentLoc(loc) { | ||
const normalizedLoc = Object.assign({}, loc); | ||
const normalizedLoc = { ...loc }; | ||
delete normalizedLoc.endToken; | ||
@@ -153,0 +151,0 @@ delete normalizedLoc.startToken; |
@@ -1,4 +0,4 @@ | ||
import { Transformer } from '@jest/transform'; | ||
export declare const getCacheKey: Transformer['getCacheKey']; | ||
export declare const process: Transformer['process']; | ||
import type { Transformer } from '@jest/transform'; | ||
declare const transformer: Transformer; | ||
export default transformer; | ||
//# sourceMappingURL=jest-simple.d.ts.map |
@@ -6,31 +6,34 @@ import { createHash } from 'crypto'; | ||
const THIS_FILE = readFileSync(__filename); | ||
export const getCacheKey = function getCacheKey(fileData, filename) { | ||
return createHash('md5') | ||
.update(THIS_FILE) | ||
.update(fileData) | ||
.update(filename) | ||
.digest('hex'); | ||
}; | ||
export const process = function process(rawSource) { | ||
const { imports, source } = extractImports(rawSource); | ||
const utilityImports = ` | ||
var {print, parse} = require('graphql'); | ||
var {cleanDocument, toSimpleDocument} = require(${JSON.stringify(`${__dirname}/document.js`)}); | ||
`; | ||
const importSource = imports | ||
.map((imported, index) => `var importedDocument${index} = require(${JSON.stringify(imported)});`) | ||
.join('\n'); | ||
const appendDefinitionsSource = imports | ||
.map((_, index) => `document.definitions.push.apply(document.definitions, parse(importedDocument${index}.source).definitions);`) | ||
.join('\n'); | ||
return ` | ||
${utilityImports} | ||
${importSource} | ||
const transformer = { | ||
getCacheKey(fileData, filename) { | ||
return createHash('md5') | ||
.update(THIS_FILE) | ||
.update(fileData) | ||
.update(filename) | ||
.digest('hex'); | ||
}, | ||
process(rawSource) { | ||
const { imports, source } = extractImports(rawSource); | ||
const utilityImports = ` | ||
var {print, parse} = require('graphql'); | ||
var {cleanDocument, toSimpleDocument} = require(${JSON.stringify(`${__dirname}/document.js`)}); | ||
`; | ||
const importSource = imports | ||
.map((imported, index) => `var importedDocument${index} = require(${JSON.stringify(imported)});`) | ||
.join('\n'); | ||
const appendDefinitionsSource = imports | ||
.map((_, index) => `document.definitions.push.apply(document.definitions, parse(importedDocument${index}.source).definitions);`) | ||
.join('\n'); | ||
return ` | ||
${utilityImports} | ||
${importSource} | ||
var document = ${JSON.stringify(parse(source))}; | ||
var document = ${JSON.stringify(parse(source))}; | ||
${appendDefinitionsSource} | ||
${appendDefinitionsSource} | ||
module.exports = toSimpleDocument(cleanDocument(document, {removeUnused: false})); | ||
`; | ||
module.exports = toSimpleDocument(cleanDocument(document, {removeUnused: false})); | ||
`; | ||
}, | ||
}; | ||
export default transformer; |
@@ -1,4 +0,4 @@ | ||
import { Transformer } from '@jest/transform'; | ||
export declare const getCacheKey: Transformer['getCacheKey']; | ||
export declare const process: Transformer['process']; | ||
import type { Transformer } from '@jest/transform'; | ||
declare const transformer: Transformer; | ||
export default transformer; | ||
//# sourceMappingURL=jest.d.ts.map |
@@ -6,31 +6,34 @@ import { createHash } from 'crypto'; | ||
const THIS_FILE = readFileSync(__filename); | ||
export const getCacheKey = function getCacheKey(fileData, filename) { | ||
return createHash('md5') | ||
.update(THIS_FILE) | ||
.update(fileData) | ||
.update(filename) | ||
.digest('hex'); | ||
}; | ||
export const process = function process(rawSource) { | ||
const { imports, source } = extractImports(rawSource); | ||
const utilityImports = ` | ||
var {print} = require('graphql'); | ||
var {cleanDocument} = require(${JSON.stringify(`${__dirname}/document.js`)}); | ||
`; | ||
const importSource = imports | ||
.map((imported, index) => `var importedDocument${index} = require(${JSON.stringify(imported)});`) | ||
.join('\n'); | ||
const appendDefinitionsSource = imports | ||
.map((_, index) => `document.definitions.push.apply(document.definitions, importedDocument${index}.definitions);`) | ||
.join('\n'); | ||
return ` | ||
${utilityImports} | ||
${importSource} | ||
const transformer = { | ||
getCacheKey(fileData, filename) { | ||
return createHash('md5') | ||
.update(THIS_FILE) | ||
.update(fileData) | ||
.update(filename) | ||
.digest('hex'); | ||
}, | ||
process(rawSource) { | ||
const { imports, source } = extractImports(rawSource); | ||
const utilityImports = ` | ||
var {print} = require('graphql'); | ||
var {cleanDocument} = require(${JSON.stringify(`${__dirname}/document.js`)}); | ||
`; | ||
const importSource = imports | ||
.map((imported, index) => `var importedDocument${index} = require(${JSON.stringify(imported)});`) | ||
.join('\n'); | ||
const appendDefinitionsSource = imports | ||
.map((_, index) => `document.definitions.push.apply(document.definitions, importedDocument${index}.definitions);`) | ||
.join('\n'); | ||
return ` | ||
${utilityImports} | ||
${importSource} | ||
var document = ${JSON.stringify(parse(source))}; | ||
var document = ${JSON.stringify(parse(source))}; | ||
${appendDefinitionsSource} | ||
${appendDefinitionsSource} | ||
module.exports = cleanDocument(document, {removeUnused: false}); | ||
`; | ||
module.exports = cleanDocument(document, {removeUnused: false}); | ||
`; | ||
}, | ||
}; | ||
export default transformer; |
@@ -1,1 +0,4 @@ | ||
module.exports = require("./build/cjs/index.js"); | ||
function interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
module.exports = interopRequireDefault(require("./build/cjs/index.js")); |
@@ -1,1 +0,2 @@ | ||
export * from "./build/ts/jest-simple"; | ||
export * from "./build/ts/jest-simple"; | ||
export {default} from "./build/ts/jest-simple"; |
@@ -1,1 +0,4 @@ | ||
module.exports = require("./build/cjs/jest-simple.js"); | ||
function interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
module.exports = interopRequireDefault(require("./build/cjs/jest-simple.js")); |
@@ -1,1 +0,2 @@ | ||
export * from "./build/ts/jest"; | ||
export * from "./build/ts/jest"; | ||
export {default} from "./build/ts/jest"; |
@@ -1,1 +0,4 @@ | ||
module.exports = require("./build/cjs/jest.js"); | ||
function interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
module.exports = interopRequireDefault(require("./build/cjs/jest.js")); |
{ | ||
"name": "graphql-mini-transforms", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"license": "MIT", | ||
@@ -27,3 +27,3 @@ "description": "Transformers for importing .graphql files in various build tools.", | ||
"dependencies": { | ||
"@jest/transform": "^26.6.2", | ||
"@jest/transform": "^27.0.2", | ||
"@types/fs-extra": "^9.0.11", | ||
@@ -94,3 +94,3 @@ "@types/webpack": "^4.41.11", | ||
], | ||
"gitHead": "6ef2424f75baf26bacbb9970cc7f47b76099d1cd" | ||
"gitHead": "bb7021130d88413cdfe08034e3bb6b3ed6617b8e" | ||
} |
@@ -1,1 +0,4 @@ | ||
module.exports = require("./build/cjs/webpack-loader.js"); | ||
function interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
module.exports = interopRequireDefault(require("./build/cjs/webpack-loader.js")); |
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
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
478308
1123
+ Added@jest/transform@27.5.1(transitive)
+ Added@jest/types@27.5.1(transitive)
+ Added@types/yargs@16.0.9(transitive)
+ Addedcaniuse-lite@1.0.30001699(transitive)
+ Addedci-info@3.9.0(transitive)
+ Addedelectron-to-chromium@1.5.101(transitive)
+ Addedjest-haste-map@27.5.1(transitive)
+ Addedjest-regex-util@27.5.1(transitive)
+ Addedjest-serializer@27.5.1(transitive)
+ Addedjest-util@27.5.1(transitive)
+ Addedjest-worker@27.5.1(transitive)
+ Addedsupports-color@8.1.1(transitive)
- Removed@cnakazawa/watch@1.0.4(transitive)
- Removed@jest/transform@26.6.2(transitive)
- Removed@jest/types@26.6.2(transitive)
- Removed@types/yargs@15.0.19(transitive)
- Removedanymatch@2.0.0(transitive)
- Removedarr-diff@4.0.0(transitive)
- Removedarr-flatten@1.1.0(transitive)
- Removedarr-union@3.1.0(transitive)
- Removedarray-unique@0.3.2(transitive)
- Removedassign-symbols@1.0.0(transitive)
- Removedatob@2.1.2(transitive)
- Removedbase@0.11.2(transitive)
- Removedbraces@2.3.2(transitive)
- Removedcache-base@1.0.1(transitive)
- Removedcaniuse-lite@1.0.30001700(transitive)
- Removedcapture-exit@2.0.0(transitive)
- Removedci-info@2.0.0(transitive)
- Removedclass-utils@0.3.6(transitive)
- Removedcollection-visit@1.0.0(transitive)
- Removedcomponent-emitter@1.3.1(transitive)
- Removedcopy-descriptor@0.1.1(transitive)
- Removedcross-spawn@6.0.6(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddecode-uri-component@0.2.2(transitive)
- Removeddefine-property@0.2.51.0.02.0.2(transitive)
- Removedelectron-to-chromium@1.5.102(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedexec-sh@0.3.6(transitive)
- Removedexeca@1.0.0(transitive)
- Removedexpand-brackets@2.1.4(transitive)
- Removedextend-shallow@2.0.13.0.2(transitive)
- Removedextglob@2.0.4(transitive)
- Removedfill-range@4.0.0(transitive)
- Removedfor-in@1.0.2(transitive)
- Removedfragment-cache@0.2.1(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-stream@4.1.0(transitive)
- Removedget-value@2.0.6(transitive)
- Removedhas-value@0.3.11.0.0(transitive)
- Removedhas-values@0.1.41.0.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedis-accessor-descriptor@1.0.1(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-ci@2.0.0(transitive)
- Removedis-data-descriptor@1.0.1(transitive)
- Removedis-descriptor@0.1.71.0.3(transitive)
- Removedis-extendable@0.1.11.0.1(transitive)
- Removedis-number@3.0.0(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedis-windows@1.0.2(transitive)
- Removedisarray@1.0.0(transitive)
- Removedisexe@2.0.0(transitive)
- Removedisobject@2.1.03.0.1(transitive)
- Removedjest-haste-map@26.6.2(transitive)
- Removedjest-regex-util@26.0.0(transitive)
- Removedjest-serializer@26.6.2(transitive)
- Removedjest-util@26.6.2(transitive)
- Removedjest-worker@26.6.2(transitive)
- Removedkind-of@3.2.24.0.06.0.3(transitive)
- Removedmap-cache@0.2.2(transitive)
- Removedmap-visit@1.0.0(transitive)
- Removedmicromatch@3.1.10(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmixin-deep@1.3.2(transitive)
- Removedms@2.0.0(transitive)
- Removednanomatch@1.2.13(transitive)
- Removednice-try@1.0.5(transitive)
- Removednormalize-path@2.1.1(transitive)
- Removednpm-run-path@2.0.2(transitive)
- Removedobject-copy@0.1.0(transitive)
- Removedobject-visit@1.0.1(transitive)
- Removedobject.pick@1.3.0(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedpascalcase@0.1.1(transitive)
- Removedpath-key@2.0.1(transitive)
- Removedposix-character-classes@0.1.1(transitive)
- Removedpump@3.0.2(transitive)
- Removedregex-not@1.0.2(transitive)
- Removedremove-trailing-separator@1.1.0(transitive)
- Removedrepeat-element@1.1.4(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedresolve-url@0.2.1(transitive)
- Removedret@0.1.15(transitive)
- Removedrsvp@4.8.5(transitive)
- Removedsafe-regex@1.1.0(transitive)
- Removedsane@4.1.0(transitive)
- Removedsemver@5.7.2(transitive)
- Removedset-value@2.0.1(transitive)
- Removedshebang-command@1.2.0(transitive)
- Removedshebang-regex@1.0.0(transitive)
- Removedsnapdragon@0.8.2(transitive)
- Removedsnapdragon-node@2.1.1(transitive)
- Removedsnapdragon-util@3.0.1(transitive)
- Removedsource-map@0.5.7(transitive)
- Removedsource-map-resolve@0.5.3(transitive)
- Removedsource-map-url@0.4.1(transitive)
- Removedsplit-string@3.1.0(transitive)
- Removedstatic-extend@0.1.2(transitive)
- Removedstrip-eof@1.0.0(transitive)
- Removedto-object-path@0.3.0(transitive)
- Removedto-regex@3.0.2(transitive)
- Removedto-regex-range@2.1.1(transitive)
- Removedunion-value@1.0.1(transitive)
- Removedunset-value@1.0.0(transitive)
- Removedurix@0.1.0(transitive)
- Removeduse@3.1.1(transitive)
- Removedwhich@1.3.1(transitive)
Updated@jest/transform@^27.0.2