graphql-mini-transforms
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -1,47 +0,21 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toSimpleDocument = exports.extractImports = exports.cleanDocument = void 0; | ||
var tslib_1 = require("tslib"); | ||
var crypto_1 = require("crypto"); | ||
var graphql_1 = require("graphql"); | ||
var IMPORT_REGEX = /^#import\s+['"]([^'"]*)['"];?[\s\n]*/gm; | ||
var DEFAULT_NAME = 'Operation'; | ||
function cleanDocument(document, _a) { | ||
var e_1, _b, e_2, _c; | ||
var _d = (_a === void 0 ? {} : _a).removeUnused, removeUnused = _d === void 0 ? true : _d; | ||
import { createHash } from 'crypto'; | ||
import { print, parse, } from 'graphql'; | ||
const IMPORT_REGEX = /^#import\s+['"]([^'"]*)['"];?[\s\n]*/gm; | ||
const DEFAULT_NAME = 'Operation'; | ||
export function cleanDocument(document, { removeUnused = true } = {}) { | ||
if (removeUnused) { | ||
removeUnusedDefinitions(document); | ||
} | ||
try { | ||
for (var _e = tslib_1.__values(document.definitions), _f = _e.next(); !_f.done; _f = _e.next()) { | ||
var definition = _f.value; | ||
addTypename(definition); | ||
} | ||
for (const definition of document.definitions) { | ||
addTypename(definition); | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_f && !_f.done && (_b = _e.return)) _b.call(_e); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
const normalizedSource = minifySource(print(document)); | ||
const normalizedDocument = parse(normalizedSource); | ||
for (const definition of normalizedDocument.definitions) { | ||
stripLoc(definition); | ||
} | ||
var normalizedSource = minifySource(graphql_1.print(document)); | ||
var normalizedDocument = graphql_1.parse(normalizedSource); | ||
try { | ||
for (var _g = tslib_1.__values(normalizedDocument.definitions), _h = _g.next(); !_h.done; _h = _g.next()) { | ||
var definition = _h.value; | ||
stripLoc(definition); | ||
} | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (_h && !_h.done && (_c = _g.return)) _c.call(_g); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
// This ID is a hash of the full file contents that are part of the document, | ||
// including other documents that are injected in, but excluding any unused | ||
// fragments. This is useful for things like persisted queries. | ||
var id = crypto_1.createHash('sha256').update(normalizedSource).digest('hex'); | ||
const id = createHash('sha256').update(normalizedSource).digest('hex'); | ||
Reflect.defineProperty(normalizedDocument, 'id', { | ||
@@ -61,13 +35,11 @@ value: id, | ||
} | ||
exports.cleanDocument = cleanDocument; | ||
function extractImports(rawSource) { | ||
var imports = new Set(); | ||
var source = rawSource.replace(IMPORT_REGEX, function (_, imported) { | ||
export function extractImports(rawSource) { | ||
const imports = new Set(); | ||
const source = rawSource.replace(IMPORT_REGEX, (_, imported) => { | ||
imports.add(imported); | ||
return ''; | ||
}); | ||
return { imports: tslib_1.__spread(imports), source: source }; | ||
return { imports: [...imports], source }; | ||
} | ||
exports.extractImports = extractImports; | ||
function toSimpleDocument(document) { | ||
export function toSimpleDocument(document) { | ||
var _a, _b; | ||
@@ -80,15 +52,10 @@ return { | ||
} | ||
exports.toSimpleDocument = toSimpleDocument; | ||
function operationNameForDocument(document) { | ||
var _a, _b; | ||
return (_b = (_a = document.definitions.find(function (definition) { | ||
return definition.kind === 'OperationDefinition'; | ||
})) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.value; | ||
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; | ||
} | ||
function removeUnusedDefinitions(document) { | ||
var e_3, _a; | ||
var usedDefinitions = new Set(); | ||
var dependencies = definitionDependencies(document.definitions); | ||
var markAsUsed = function (definition) { | ||
var e_4, _a; | ||
const usedDefinitions = new Set(); | ||
const dependencies = definitionDependencies(document.definitions); | ||
const markAsUsed = (definition) => { | ||
if (usedDefinitions.has(definition)) { | ||
@@ -98,32 +65,12 @@ return; | ||
usedDefinitions.add(definition); | ||
try { | ||
for (var _b = tslib_1.__values(dependencies.get(definition) || []), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var dependency = _c.value; | ||
markAsUsed(dependency); | ||
} | ||
for (const dependency of dependencies.get(definition) || []) { | ||
markAsUsed(dependency); | ||
} | ||
catch (e_4_1) { e_4 = { error: e_4_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_4) throw e_4.error; } | ||
} | ||
}; | ||
try { | ||
for (var _b = tslib_1.__values(document.definitions), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var definition = _c.value; | ||
if (definition.kind !== 'FragmentDefinition') { | ||
markAsUsed(definition); | ||
} | ||
for (const definition of document.definitions) { | ||
if (definition.kind !== 'FragmentDefinition') { | ||
markAsUsed(definition); | ||
} | ||
} | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_3) throw e_3.error; } | ||
} | ||
document.definitions = tslib_1.__spread(usedDefinitions); | ||
document.definitions = [...usedDefinitions]; | ||
} | ||
@@ -138,22 +85,20 @@ function minifySource(source) { | ||
function definitionDependencies(definitions) { | ||
var executableDefinitions = definitions.filter(function (definition) { | ||
return definition.kind === 'OperationDefinition' || | ||
definition.kind === 'FragmentDefinition'; | ||
}); | ||
var definitionsByName = new Map(executableDefinitions.map(function (definition) { return [ | ||
const executableDefinitions = definitions.filter(definition => definition.kind === 'OperationDefinition' || | ||
definition.kind === 'FragmentDefinition'); | ||
const definitionsByName = new Map(executableDefinitions.map(definition => [ | ||
definition.name ? definition.name.value : DEFAULT_NAME, | ||
definition, | ||
]; })); | ||
return new Map(executableDefinitions.map(function (executableNode) { return [ | ||
])); | ||
return new Map(executableDefinitions.map(executableNode => [ | ||
executableNode, | ||
tslib_1.__spread(collectUsedFragmentSpreads(executableNode, new Set())).map(function (usedFragment) { | ||
var definition = definitionsByName.get(usedFragment); | ||
[...collectUsedFragmentSpreads(executableNode, new Set())].map(usedFragment => { | ||
const definition = definitionsByName.get(usedFragment); | ||
if (definition == null) { | ||
throw new Error("You attempted to use the fragment '" + usedFragment + "' (in '" + (executableNode.name ? executableNode.name.value : DEFAULT_NAME) + "'), but it does not exist. Maybe you forgot to import it from another document?"); | ||
throw new Error(`You attempted to use the fragment '${usedFragment}' (in '${executableNode.name ? executableNode.name.value : DEFAULT_NAME}'), but it does not exist. Maybe you forgot to import it from another document?`); | ||
} | ||
return definition; | ||
}), | ||
]; })); | ||
])); | ||
} | ||
var TYPENAME_FIELD = { | ||
const TYPENAME_FIELD = { | ||
kind: 'Field', | ||
@@ -164,39 +109,15 @@ alias: null, | ||
function addTypename(definition) { | ||
var e_5, _a; | ||
try { | ||
for (var _b = tslib_1.__values(selectionSetsForDefinition(definition)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var selections = _c.value.selections; | ||
var hasTypename = selections.some(function (selection) { | ||
return selection.kind === 'Field' && selection.name.value === '__typename'; | ||
}); | ||
if (!hasTypename) { | ||
selections.push(TYPENAME_FIELD); | ||
} | ||
for (const { selections } of selectionSetsForDefinition(definition)) { | ||
const hasTypename = selections.some(selection => selection.kind === 'Field' && selection.name.value === '__typename'); | ||
if (!hasTypename) { | ||
selections.push(TYPENAME_FIELD); | ||
} | ||
} | ||
catch (e_5_1) { e_5 = { error: e_5_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_5) throw e_5.error; } | ||
} | ||
} | ||
function collectUsedFragmentSpreads(definition, usedSpreads) { | ||
var e_6, _a; | ||
try { | ||
for (var _b = tslib_1.__values(selectionsForDefinition(definition)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var selection = _c.value; | ||
if (selection.kind === 'FragmentSpread') { | ||
usedSpreads.add(selection.name.value); | ||
} | ||
for (const selection of selectionsForDefinition(definition)) { | ||
if (selection.kind === 'FragmentSpread') { | ||
usedSpreads.add(selection.name.value); | ||
} | ||
} | ||
catch (e_6_1) { e_6 = { error: e_6_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_6) throw e_6.error; } | ||
} | ||
return usedSpreads; | ||
@@ -210,88 +131,26 @@ } | ||
} | ||
function selectionSetsForDefinition(definition) { | ||
var _a, _b, nestedSelection, e_7_1; | ||
var e_7, _c; | ||
return tslib_1.__generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: | ||
if (!('selectionSet' in definition) || definition.selectionSet == null) { | ||
return [2 /*return*/, [][Symbol.iterator]()]; | ||
} | ||
if (!(definition.kind !== 'OperationDefinition')) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, definition.selectionSet]; | ||
case 1: | ||
_d.sent(); | ||
_d.label = 2; | ||
case 2: | ||
_d.trys.push([2, 7, 8, 9]); | ||
_a = tslib_1.__values(selectionsForDefinition(definition)), _b = _a.next(); | ||
_d.label = 3; | ||
case 3: | ||
if (!!_b.done) return [3 /*break*/, 6]; | ||
nestedSelection = _b.value; | ||
if (!('selectionSet' in nestedSelection && | ||
nestedSelection.selectionSet != null)) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, nestedSelection.selectionSet]; | ||
case 4: | ||
_d.sent(); | ||
_d.label = 5; | ||
case 5: | ||
_b = _a.next(); | ||
return [3 /*break*/, 3]; | ||
case 6: return [3 /*break*/, 9]; | ||
case 7: | ||
e_7_1 = _d.sent(); | ||
e_7 = { error: e_7_1 }; | ||
return [3 /*break*/, 9]; | ||
case 8: | ||
try { | ||
if (_b && !_b.done && (_c = _a.return)) _c.call(_a); | ||
} | ||
finally { if (e_7) throw e_7.error; } | ||
return [7 /*endfinally*/]; | ||
case 9: return [2 /*return*/]; | ||
function* selectionSetsForDefinition(definition) { | ||
if (!('selectionSet' in definition) || definition.selectionSet == null) { | ||
return [][Symbol.iterator](); | ||
} | ||
if (definition.kind !== 'OperationDefinition') { | ||
yield definition.selectionSet; | ||
} | ||
for (const nestedSelection of selectionsForDefinition(definition)) { | ||
if ('selectionSet' in nestedSelection && | ||
nestedSelection.selectionSet != null) { | ||
yield nestedSelection.selectionSet; | ||
} | ||
}); | ||
} | ||
} | ||
function selectionsForSelectionSet(_a) { | ||
var selections_1, selections_1_1, selection, e_8_1; | ||
var e_8, _b; | ||
var selections = _a.selections; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_c.trys.push([0, 6, 7, 8]); | ||
selections_1 = tslib_1.__values(selections), selections_1_1 = selections_1.next(); | ||
_c.label = 1; | ||
case 1: | ||
if (!!selections_1_1.done) return [3 /*break*/, 5]; | ||
selection = selections_1_1.value; | ||
return [4 /*yield*/, selection]; | ||
case 2: | ||
_c.sent(); | ||
if (!('selectionSet' in selection && selection.selectionSet != null)) return [3 /*break*/, 4]; | ||
return [5 /*yield**/, tslib_1.__values(selectionsForSelectionSet(selection.selectionSet))]; | ||
case 3: | ||
_c.sent(); | ||
_c.label = 4; | ||
case 4: | ||
selections_1_1 = selections_1.next(); | ||
return [3 /*break*/, 1]; | ||
case 5: return [3 /*break*/, 8]; | ||
case 6: | ||
e_8_1 = _c.sent(); | ||
e_8 = { error: e_8_1 }; | ||
return [3 /*break*/, 8]; | ||
case 7: | ||
try { | ||
if (selections_1_1 && !selections_1_1.done && (_b = selections_1.return)) _b.call(selections_1); | ||
} | ||
finally { if (e_8) throw e_8.error; } | ||
return [7 /*endfinally*/]; | ||
case 8: return [2 /*return*/]; | ||
function* selectionsForSelectionSet({ selections, }) { | ||
for (const selection of selections) { | ||
yield selection; | ||
if ('selectionSet' in selection && selection.selectionSet != null) { | ||
yield* selectionsForSelectionSet(selection.selectionSet); | ||
} | ||
}); | ||
} | ||
} | ||
function stripDocumentLoc(loc) { | ||
var normalizedLoc = tslib_1.__assign({}, loc); | ||
const normalizedLoc = Object.assign({}, loc); | ||
delete normalizedLoc.endToken; | ||
@@ -302,3 +161,2 @@ delete normalizedLoc.startToken; | ||
function stripLoc(value) { | ||
var e_9, _a; | ||
if (Array.isArray(value)) { | ||
@@ -314,16 +172,6 @@ value.forEach(stripLoc); | ||
} | ||
try { | ||
for (var _b = tslib_1.__values(Object.keys(value)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var key = _c.value; | ||
stripLoc(value[key]); | ||
} | ||
for (const key of Object.keys(value)) { | ||
stripLoc(value[key]); | ||
} | ||
catch (e_9_1) { e_9 = { error: e_9_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_9) throw e_9.error; } | ||
} | ||
} | ||
} |
@@ -1,6 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var document_1 = require("./document"); | ||
Object.defineProperty(exports, "cleanDocument", { enumerable: true, get: function () { return document_1.cleanDocument; } }); | ||
Object.defineProperty(exports, "extractImports", { enumerable: true, get: function () { return document_1.extractImports; } }); | ||
Object.defineProperty(exports, "toSimpleDocument", { enumerable: true, get: function () { return document_1.toSimpleDocument; } }); | ||
export { cleanDocument, extractImports, toSimpleDocument } from './document'; |
@@ -1,11 +0,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.process = exports.getCacheKey = void 0; | ||
var crypto_1 = require("crypto"); | ||
var fs_extra_1 = require("fs-extra"); | ||
var graphql_1 = require("graphql"); | ||
var document_1 = require("./document"); | ||
var THIS_FILE = fs_extra_1.readFileSync(__filename); | ||
exports.getCacheKey = function getCacheKey(fileData, filename) { | ||
return crypto_1.createHash('md5') | ||
import { createHash } from 'crypto'; | ||
import { readFileSync } from 'fs-extra'; | ||
import { parse } from 'graphql'; | ||
import { extractImports } from './document'; | ||
const THIS_FILE = readFileSync(__filename); | ||
export const getCacheKey = function getCacheKey(fileData, filename) { | ||
return createHash('md5') | ||
.update(THIS_FILE) | ||
@@ -16,16 +13,24 @@ .update(fileData) | ||
}; | ||
exports.process = function process(rawSource) { | ||
var _a = document_1.extractImports(rawSource), imports = _a.imports, source = _a.source; | ||
var utilityImports = "\n var {print, parse} = require('graphql');\n var {cleanDocument, toSimpleDocument} = require(" + JSON.stringify(__dirname + "/document.js") + ");\n "; | ||
var importSource = imports | ||
.map(function (imported, index) { | ||
return "var importedDocument" + index + " = require(" + JSON.stringify(imported) + ");"; | ||
}) | ||
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'); | ||
var appendDefinitionsSource = imports | ||
.map(function (_, index) { | ||
return "document.definitions.push.apply(document.definitions, parse(importedDocument" + index + ".source).definitions);"; | ||
}) | ||
const appendDefinitionsSource = imports | ||
.map((_, index) => `document.definitions.push.apply(document.definitions, parse(importedDocument${index}.source).definitions);`) | ||
.join('\n'); | ||
return "\n " + utilityImports + "\n " + importSource + "\n\n var document = " + JSON.stringify(graphql_1.parse(source)) + ";\n\n " + appendDefinitionsSource + "\n\n module.exports = toSimpleDocument(cleanDocument(document, {removeUnused: false}));\n "; | ||
return ` | ||
${utilityImports} | ||
${importSource} | ||
var document = ${JSON.stringify(parse(source))}; | ||
${appendDefinitionsSource} | ||
module.exports = toSimpleDocument(cleanDocument(document, {removeUnused: false})); | ||
`; | ||
}; |
@@ -1,11 +0,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.process = exports.getCacheKey = void 0; | ||
var crypto_1 = require("crypto"); | ||
var fs_extra_1 = require("fs-extra"); | ||
var graphql_1 = require("graphql"); | ||
var document_1 = require("./document"); | ||
var THIS_FILE = fs_extra_1.readFileSync(__filename); | ||
exports.getCacheKey = function getCacheKey(fileData, filename) { | ||
return crypto_1.createHash('md5') | ||
import { createHash } from 'crypto'; | ||
import { readFileSync } from 'fs-extra'; | ||
import { parse } from 'graphql'; | ||
import { extractImports } from './document'; | ||
const THIS_FILE = readFileSync(__filename); | ||
export const getCacheKey = function getCacheKey(fileData, filename) { | ||
return createHash('md5') | ||
.update(THIS_FILE) | ||
@@ -16,16 +13,24 @@ .update(fileData) | ||
}; | ||
exports.process = function process(rawSource) { | ||
var _a = document_1.extractImports(rawSource), imports = _a.imports, source = _a.source; | ||
var utilityImports = "\n var {print} = require('graphql');\n var {cleanDocument} = require(" + JSON.stringify(__dirname + "/document.js") + ");\n "; | ||
var importSource = imports | ||
.map(function (imported, index) { | ||
return "var importedDocument" + index + " = require(" + JSON.stringify(imported) + ");"; | ||
}) | ||
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'); | ||
var appendDefinitionsSource = imports | ||
.map(function (_, index) { | ||
return "document.definitions.push.apply(document.definitions, importedDocument" + index + ".definitions);"; | ||
}) | ||
const appendDefinitionsSource = imports | ||
.map((_, index) => `document.definitions.push.apply(document.definitions, importedDocument${index}.definitions);`) | ||
.join('\n'); | ||
return "\n " + utilityImports + "\n " + importSource + "\n\n var document = " + JSON.stringify(graphql_1.parse(source)) + ";\n\n " + appendDefinitionsSource + "\n\n module.exports = cleanDocument(document, {removeUnused: false});\n "; | ||
return ` | ||
${utilityImports} | ||
${importSource} | ||
var document = ${JSON.stringify(parse(source))}; | ||
${appendDefinitionsSource} | ||
module.exports = cleanDocument(document, {removeUnused: false}); | ||
`; | ||
}; |
@@ -1,106 +0,56 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var path_1 = require("path"); | ||
var graphql_1 = require("graphql"); | ||
var loader_utils_1 = require("loader-utils"); | ||
var document_1 = require("./document"); | ||
function graphQLLoader(source) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var done, _a, simple, document_2, _b, exported, error_1; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
this.cacheable(); | ||
done = this.async(); | ||
_a = loader_utils_1.getOptions(this).simple, simple = _a === void 0 ? false : _a; | ||
if (done == null) { | ||
throw new Error('@shopify/graphql-loader does not support synchronous processing'); | ||
} | ||
_c.label = 1; | ||
case 1: | ||
_c.trys.push([1, 3, , 4]); | ||
_b = document_1.cleanDocument; | ||
return [4 /*yield*/, loadDocument(source, this.context, this)]; | ||
case 2: | ||
document_2 = _b.apply(void 0, [_c.sent()]); | ||
exported = simple ? document_1.toSimpleDocument(document_2) : document_2; | ||
done(null, "export default JSON.parse(" + JSON.stringify(JSON.stringify(exported)) + ");"); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
error_1 = _c.sent(); | ||
done(error_1); | ||
return [3 /*break*/, 4]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
import { dirname } from 'path'; | ||
import { parse } from 'graphql'; | ||
import { getOptions } from 'loader-utils'; | ||
import { cleanDocument, extractImports, toSimpleDocument } from './document'; | ||
export default async function graphQLLoader(source) { | ||
this.cacheable(); | ||
const done = this.async(); | ||
const { simple = false } = getOptions(this); | ||
if (done == null) { | ||
throw new Error('@shopify/graphql-loader does not support synchronous processing'); | ||
} | ||
try { | ||
const document = cleanDocument(await loadDocument(source, this.context, this)); | ||
const exported = simple ? toSimpleDocument(document) : document; | ||
done(null, `export default JSON.parse(${JSON.stringify(JSON.stringify(exported))});`); | ||
} | ||
catch (error) { | ||
done(error); | ||
} | ||
} | ||
exports.default = graphQLLoader; | ||
function loadDocument(rawSource, resolveContext, loader) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var normalizedSource, _a, imports, source, document, resolvedImports, resolvedImports_1, resolvedImports_1_1, definitions; | ||
var e_1, _b, _c; | ||
var _this = this; | ||
return tslib_1.__generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: | ||
normalizedSource = typeof rawSource === 'string' ? rawSource : rawSource.toString(); | ||
_a = document_1.extractImports(normalizedSource), imports = _a.imports, source = _a.source; | ||
document = graphql_1.parse(source); | ||
if (imports.length === 0) { | ||
return [2 /*return*/, document]; | ||
} | ||
return [4 /*yield*/, Promise.all(imports.map(function (imported) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var resolvedPath, source; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, new Promise(function (resolve, reject) { | ||
loader.resolve(resolveContext, imported, function (error, result) { | ||
if (error) { | ||
reject(error); | ||
} | ||
else { | ||
loader.addDependency(result); | ||
resolve(result); | ||
} | ||
}); | ||
})]; | ||
case 1: | ||
resolvedPath = _a.sent(); | ||
return [4 /*yield*/, new Promise(function (resolve, reject) { | ||
loader.fs.readFile(resolvedPath, function (error, result) { | ||
if (error) { | ||
reject(error); | ||
} | ||
else { | ||
resolve(result); | ||
} | ||
}); | ||
})]; | ||
case 2: | ||
source = _a.sent(); | ||
return [2 /*return*/, loadDocument(source, path_1.dirname(resolvedPath), loader)]; | ||
} | ||
}); | ||
}); }))]; | ||
case 1: | ||
resolvedImports = _d.sent(); | ||
try { | ||
for (resolvedImports_1 = tslib_1.__values(resolvedImports), resolvedImports_1_1 = resolvedImports_1.next(); !resolvedImports_1_1.done; resolvedImports_1_1 = resolvedImports_1.next()) { | ||
definitions = resolvedImports_1_1.value.definitions; | ||
(_c = document.definitions).push.apply(_c, tslib_1.__spread(definitions)); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (resolvedImports_1_1 && !resolvedImports_1_1.done && (_b = resolvedImports_1.return)) _b.call(resolvedImports_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return [2 /*return*/, document]; | ||
} | ||
async function loadDocument(rawSource, resolveContext, loader) { | ||
const normalizedSource = typeof rawSource === 'string' ? rawSource : rawSource.toString(); | ||
const { imports, source } = extractImports(normalizedSource); | ||
const document = parse(source); | ||
if (imports.length === 0) { | ||
return document; | ||
} | ||
const resolvedImports = await Promise.all(imports.map(async (imported) => { | ||
const resolvedPath = await new Promise((resolve, reject) => { | ||
loader.resolve(resolveContext, imported, (error, result) => { | ||
if (error) { | ||
reject(error); | ||
} | ||
else { | ||
loader.addDependency(result); | ||
resolve(result); | ||
} | ||
}); | ||
}); | ||
}); | ||
const source = await new Promise((resolve, reject) => { | ||
loader.fs.readFile(resolvedPath, (error, result) => { | ||
if (error) { | ||
reject(error); | ||
} | ||
else { | ||
resolve(result); | ||
} | ||
}); | ||
}); | ||
return loadDocument(source, dirname(resolvedPath), loader); | ||
})); | ||
for (const { definitions } of resolvedImports) { | ||
document.definitions.push(...definitions); | ||
} | ||
return document; | ||
} |
@@ -8,11 +8,17 @@ # Changelog | ||
<!-- ## [Unreleased] --> | ||
<!-- ## Unreleased --> | ||
## [2.0.2] - 2021-03-23 | ||
## 2.0.3 - 2021-04-13 | ||
### Changed | ||
- Removed dependency on tslib, as we no-longer compile with `tsc`. [#1829](https://github.com/Shopify/quilt/pull/1829) | ||
## 2.0.2 - 2021-03-23 | ||
### Changed | ||
- Updated `jest` and `jest-simple` to not rely on cjs-only concepts [[#1788](https://github.com/Shopify/quilt/pull/1788)] | ||
## [2.0.1] - 2021-03-16 | ||
## 2.0.1 - 2021-03-16 | ||
@@ -23,3 +29,3 @@ ### Changed | ||
## [2.0.0] - 2021-03-11 | ||
## 2.0.0 - 2021-03-11 | ||
@@ -32,3 +38,3 @@ ### Changed | ||
## [1.3.0] - 2021-02-24 | ||
## 1.3.0 - 2021-02-24 | ||
@@ -39,3 +45,3 @@ ### Added | ||
## [1.2.0] - 2020-04-27 | ||
## 1.2.0 - 2020-04-27 | ||
@@ -47,3 +53,3 @@ ### Added | ||
## [1.1.0] - 2020-04-14 | ||
## 1.1.0 - 2020-04-14 | ||
@@ -57,12 +63,12 @@ ### Changed | ||
## [1.0.3] - 2019-04-29 | ||
## 1.0.3 - 2019-04-29 | ||
- Fixed issues with the Jest loader ([#81](https://github.com/Shopify/graphql-tools-web/pull/81)) | ||
## [1.0.2] - 2019-04-29 | ||
## 1.0.2 - 2019-04-29 | ||
- Fixed issues with the Webpack loader when a document had one or more imports ([#80](https://github.com/Shopify/graphql-tools-web/pull/80)) | ||
## [1.0.0] - 2019-04-09 | ||
## 1.0.0 - 2019-04-09 | ||
Initial release |
{ | ||
"name": "graphql-mini-transforms", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"license": "MIT", | ||
@@ -8,5 +8,2 @@ "description": "Transformers for importing .graphql files in various build tools.", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
"build": "tsc --p tsconfig.json" | ||
}, | ||
"sideEffects": false, | ||
@@ -33,5 +30,4 @@ "publishConfig": { | ||
"graphql": ">=14.5.0 <15.0.0", | ||
"graphql-typed": "^0.7.1", | ||
"loader-utils": "^2.0.0", | ||
"tslib": "^1.14.1" | ||
"graphql-typed": "^0.7.2", | ||
"loader-utils": "^2.0.0" | ||
}, | ||
@@ -38,0 +34,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7
98492
1722
- Removedtslib@^1.14.1
- Removedtslib@1.14.1(transitive)
Updatedgraphql-typed@^0.7.2