graphql-parse-resolve-info
Advanced tools
Comparing version 4.0.0-beta.2 to 4.0.0-beta.4
@@ -7,7 +7,2 @@ "use strict"; | ||
exports.getAlias = exports.simplify = exports.parse = undefined; | ||
var _assign = require("babel-runtime/core-js/object/assign"); | ||
var _assign2 = _interopRequireDefault(_assign); | ||
exports.getAliasFromResolveInfo = getAliasFromResolveInfo; | ||
@@ -33,2 +28,29 @@ exports.parseResolveInfo = parseResolveInfo; | ||
function getArgVal(resolveInfo, argument) { | ||
if (argument.kind === "Variable") { | ||
return resolveInfo.variableValues[argument.name.value]; | ||
} else if (argument.kind === "BooleanValue") { | ||
return argument.value; | ||
} | ||
} | ||
function skipField(resolveInfo, { directives = [] }) { | ||
let skip = false; | ||
directives.forEach(directive => { | ||
const directiveName = directive.name.value; | ||
if (Array.isArray(directive.arguments)) { | ||
const ifArgumentAst = directive.arguments.find(arg => arg.name && arg.name.value === "if"); | ||
if (ifArgumentAst) { | ||
const argumentValueAst = ifArgumentAst.value; | ||
if (directiveName === "skip") { | ||
skip = skip || getArgVal(resolveInfo, argumentValueAst); | ||
} else if (directiveName === "include") { | ||
skip = skip || !getArgVal(resolveInfo, argumentValueAst); | ||
} | ||
} | ||
} | ||
}); | ||
return skip; | ||
} | ||
// Originally based on https://github.com/tjmehta/graphql-parse-fields | ||
@@ -107,3 +129,5 @@ | ||
debug("%s[%d] Processing AST %d of %d; kind = %s", depth, instance, idx + 1, asts.length, selectionVal.kind); | ||
if (selectionVal.kind === "Field") { | ||
if (skipField(resolveInfo, selectionVal)) { | ||
debug("%s[%d] IGNORING due to directive", depth, instance); | ||
} else if (selectionVal.kind === "Field") { | ||
const val = selectionVal; | ||
@@ -201,3 +225,3 @@ const name = val.name && val.name.value; | ||
if ((0, _graphql.isCompositeType)(StrippedType)) { | ||
(0, _assign2.default)(fields, fieldsByTypeName[StrippedType.name]); | ||
Object.assign(fields, fieldsByTypeName[StrippedType.name]); | ||
if (StrippedType instanceof _graphql.GraphQLObjectType) { | ||
@@ -207,7 +231,7 @@ const ObjectType = StrippedType; | ||
for (const Interface of ObjectType.getInterfaces()) { | ||
(0, _assign2.default)(fields, fieldsByTypeName[Interface.name]); | ||
Object.assign(fields, fieldsByTypeName[Interface.name]); | ||
} | ||
} | ||
} | ||
return (0, _assign2.default)({}, parsedResolveInfoFragment, { | ||
return Object.assign({}, parsedResolveInfoFragment, { | ||
fields | ||
@@ -214,0 +238,0 @@ }); |
{ | ||
"name": "graphql-parse-resolve-info", | ||
"version": "4.0.0-beta.2", | ||
"version": "4.0.0-beta.4", | ||
"description": "Parse GraphQLResolveInfo (the 4th argument of resolve) into a simple tree", | ||
"main": "node8plus/index.js", | ||
"scripts": { | ||
"test": "jest .", | ||
"prepublish": "mkdir -p node8plus && babel -s true --out-dir node8plus src && ../../node_modules/.bin/flow-copy-source src node8plus", | ||
"test": "jest", | ||
"prepublish": "mkdir -p node8plus && babel -s true --out-dir node8plus src && flow-copy-source src node8plus", | ||
"watch": "mkdir -p node8plus && babel -s true --watch --out-dir node8plus src" | ||
@@ -34,3 +34,3 @@ }, | ||
"flow-copy-source": "^1.2.0", | ||
"jest": "20.0.4" | ||
"jest": "^20.0.4" | ||
}, | ||
@@ -41,3 +41,2 @@ "jest": { | ||
"dependencies": { | ||
"babel-runtime": ">=6 <7", | ||
"debug": ">=2 <3" | ||
@@ -44,0 +43,0 @@ }, |
@@ -46,2 +46,31 @@ // @flow | ||
function getArgVal(resolveInfo, argument) { | ||
if (argument.kind === "Variable") { | ||
return resolveInfo.variableValues[argument.name.value]; | ||
} else if (argument.kind === "BooleanValue") { | ||
return argument.value; | ||
} | ||
} | ||
function skipField(resolveInfo, { directives = [] }) { | ||
let skip = false; | ||
directives.forEach(directive => { | ||
const directiveName = directive.name.value; | ||
if (Array.isArray(directive.arguments)) { | ||
const ifArgumentAst = directive.arguments.find( | ||
arg => arg.name && arg.name.value === "if" | ||
); | ||
if (ifArgumentAst) { | ||
const argumentValueAst = ifArgumentAst.value; | ||
if (directiveName === "skip") { | ||
skip = skip || getArgVal(resolveInfo, argumentValueAst); | ||
} else if (directiveName === "include") { | ||
skip = skip || !getArgVal(resolveInfo, argumentValueAst); | ||
} | ||
} | ||
} | ||
}); | ||
return skip; | ||
} | ||
// Originally based on https://github.com/tjmehta/graphql-parse-fields | ||
@@ -154,3 +183,5 @@ | ||
); | ||
if (selectionVal.kind === "Field") { | ||
if (skipField(resolveInfo, selectionVal)) { | ||
debug("%s[%d] IGNORING due to directive", depth, instance); | ||
} else if (selectionVal.kind === "Field") { | ||
const val: FieldNode = selectionVal; | ||
@@ -157,0 +188,0 @@ const name = val.name && val.name.value; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
2
61102
7
539
- Removedbabel-runtime@>=6 <7
- Removedbabel-runtime@6.26.0(transitive)
- Removedcore-js@2.6.12(transitive)
- Removedregenerator-runtime@0.11.1(transitive)