babel-plugin-inline-import-graphql-ast
Advanced tools
Comparing version 2.3.8 to 2.4.0
@@ -7,5 +7,23 @@ "use strict"; | ||
exports.createDocPerOp = createDocPerOp; | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
var definitionRefs; | ||
function createDocPerOp(doc) { | ||
function createDocPerOp(_ref) { | ||
var doc = _ref.ast, | ||
isOnlyFrags = _ref.isOnlyFrags; | ||
if (doc.definitions.length === 1) { | ||
@@ -30,4 +48,15 @@ var name = doc.definitions[0].name; | ||
var docs = {}; | ||
if (!isOnlyFrags) { | ||
while (doc.definitions[0].kind !== 'OperationDefinition') { | ||
var _doc$definitions = _toArray(doc.definitions), | ||
head = _doc$definitions[0], | ||
tail = _doc$definitions.slice(1); | ||
doc.definitions = _toConsumableArray(tail).concat([head]); | ||
} | ||
} | ||
doc.definitions.forEach(function (op, i) { | ||
if (op.kind === 'OperationDefinition') { | ||
if (op.kind === 'OperationDefinition' || op.kind === 'FragmentDefinition') { | ||
if (!op.name) { | ||
@@ -50,9 +79,9 @@ throw new Error('Names are required for a document with multiple Queries/Mutations'); | ||
function collectRefs(_ref, refs) { | ||
var kind = _ref.kind, | ||
type = _ref.type, | ||
name = _ref.name, | ||
selectionSet = _ref.selectionSet, | ||
variableDefinitions = _ref.variableDefinitions, | ||
definitions = _ref.definitions; | ||
function collectRefs(_ref2, refs) { | ||
var kind = _ref2.kind, | ||
type = _ref2.type, | ||
name = _ref2.name, | ||
selectionSet = _ref2.selectionSet, | ||
variableDefinitions = _ref2.variableDefinitions, | ||
definitions = _ref2.definitions; | ||
@@ -59,0 +88,0 @@ if (kind === 'FragmentSpread') { |
@@ -44,7 +44,8 @@ "use strict"; | ||
filepath = (0, _path.isAbsolute)(filepath) ? filepath : (0, _path.join)(callerDirname(), filepath); | ||
var source = (0, _fs.readFileSync)(filepath).toString(); // If the file doesn't contain ops return raw text, else parse and return docs object. | ||
var source = (0, _fs.readFileSync)(filepath).toString(); // If the file doesn't contain ops return raw text, else parse and return docsMap object. | ||
if (isSchemaLike(source)) return source; | ||
var docs = (0, _multiOp.createDocPerOp)(processDoc(createDoc(source, filepath, resolve))); | ||
return nowrap && Object.keys(docs).length <= 2 ? docs.default : docs; | ||
var doc = processDoc(createDoc(source, filepath, resolve)); | ||
var docsMap = (0, _multiOp.createDocPerOp)(doc); | ||
return nowrap && !doc.isMultiOp ? docsMap.default : docsMap; | ||
}; | ||
@@ -134,2 +135,17 @@ | ||
return ast; | ||
}, | ||
get isMultiOp() { | ||
var reducer = function reducer(acc, def) { | ||
return def.kind === 'OperationDefinition' ? acc += 1 : acc; | ||
}; | ||
var opCount = ast.definitions.reduce(reducer, 0); | ||
return opCount > 1; | ||
}, | ||
get isOnlyFrags() { | ||
return ast.definitions.every(function (d) { | ||
return d.kind === 'FragmentDefinition'; | ||
}); | ||
} | ||
@@ -145,3 +161,3 @@ | ||
doc.makeSourceEnumerable(); | ||
return doc.ast; | ||
return doc; | ||
} |
# ChangeLog | ||
## v2.4.0 (May 18, 2018) | ||
### Features | ||
* Add support for fragment-only files with multiple fragments | ||
* Add support for importing fragments from mixed files (containing fragments and operations) | ||
## v2.3.8 (May 15, 2018) | ||
@@ -4,0 +11,0 @@ |
{ | ||
"name": "babel-plugin-inline-import-graphql-ast", | ||
"version": "2.3.8", | ||
"version": "2.4.0", | ||
"description": "Babel plugin to make .gql/.graphql files importable", | ||
@@ -5,0 +5,0 @@ "author": "Alexander Roberts <detrohutt@gmail.com>", |
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
26464
308