@coderich/graphql-shape
Advanced tools
Comparing version 2.0.0 to 2.1.0
{ | ||
"name": "@coderich/graphql-shape", | ||
"main": "src/GraphQLShape.js", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"publishConfig": { | ||
@@ -18,4 +18,5 @@ "access": "public" | ||
"dependencies": { | ||
"@coderich/util": "0.1.16", | ||
"jsonpath-plus": "^8.0.0" | ||
"@coderich/util": "0.1.17", | ||
"jsonpath-plus": "^8.0.0", | ||
"lodash.get": "4.4.2" | ||
}, | ||
@@ -22,0 +23,0 @@ "devDependencies": { |
@@ -0,1 +1,2 @@ | ||
const get = require('lodash.get'); | ||
const Util = require('@coderich/util'); | ||
@@ -45,2 +46,4 @@ | ||
// Utility methods | ||
exports.get = get; | ||
exports.set = Util.set; | ||
exports.nvl = Util.nvl; | ||
@@ -52,1 +55,2 @@ exports.uvl = Util.uvl; | ||
exports.unflatten = Util.unflatten; | ||
exports.pick = (v, ...rest) => rest.flat().reduce((prev, key) => Object.assign(prev, { [key]: v[key] }), {}); |
@@ -20,3 +20,4 @@ const Util = require('@coderich/util'); | ||
const fragments = {}; | ||
let target = transforms, isFragment = false, counter = 0; | ||
const deleteNodes = new WeakMap(); | ||
let target = transforms, isFragment = false, counter = 0, field; | ||
@@ -51,8 +52,9 @@ // Parse out directives while building transforms | ||
case Kind.DIRECTIVE: { | ||
if (name === options.name) { | ||
if ([options.name, `_${options.name}`].includes(name)) { | ||
const ops = node.arguments.map((arg) => { | ||
const key = arg.name.value; | ||
const value = GraphQLShape.#resolveNodeValue(arg.value); | ||
if (name === `_${options.name}`) deleteNodes.set(field.name, false); | ||
return { [key]: value }; | ||
}); | ||
}).filter(Boolean); | ||
@@ -68,2 +70,3 @@ const $paths = isFragment ? fpaths : paths; | ||
else paths.push(key); | ||
field = node; | ||
break; | ||
@@ -92,2 +95,3 @@ } | ||
else paths.pop(); | ||
if (deleteNodes.has(node.name)) return null; | ||
break; | ||
@@ -116,6 +120,6 @@ } | ||
static transform(data, transforms = []) { | ||
const hoisted = []; | ||
// Apply transformations (in place) | ||
transforms.forEach(({ key, ops = [] }) => { | ||
const hoisted = []; | ||
// We assign data here because it's possible to modify the root/data itself (key: '') | ||
@@ -131,3 +135,12 @@ data = Util.pathmap(key, data, (value, info) => { | ||
const json = [value, info.parent, data][['self', 'parent', 'root'].indexOf(fn)]; | ||
value = Util.isPlainObjectOrArray(json) ? JSONPath({ path: mixed, json, wrap: false }) : json; | ||
try { | ||
value = Util.isPlainObjectOrArray(json) ? JSONPath({ path: mixed, json, wrap: false }) : json; | ||
} catch (e) { | ||
e.data = { json, mixed }; | ||
console.log(json); | ||
console.log(mixed); | ||
throw e; | ||
} | ||
break; | ||
@@ -139,2 +152,3 @@ } | ||
value = Util.map(value, v => GraphQLShape.#resolveValueFunction(v, values, fnName, args)); | ||
// value = Util.map(value, v => GraphQLShape.#resolveValueFunction(v, values, fnName, args)); | ||
}); | ||
@@ -160,7 +174,7 @@ break; | ||
}); | ||
// Delete any hoisted keys | ||
hoisted.forEach(hoist => delete hoist.parent[hoist.key]); | ||
}); | ||
// Delete any hoisted keys | ||
hoisted.forEach(({ key, parent }) => delete parent[key]); | ||
return data; // For convenience (and testing) | ||
@@ -167,0 +181,0 @@ } |
9221
250
4
+ Addedlodash.get@4.4.2
+ Added@coderich/util@0.1.17(transitive)
+ Addedlodash.get@4.4.2(transitive)
- Removed@coderich/util@0.1.16(transitive)
Updated@coderich/util@0.1.17