@envelop/extended-validation
Advanced tools
Comparing version 0.2.0 to 0.2.1-alpha-81eaa39.0
16
index.js
@@ -8,2 +8,3 @@ 'use strict'; | ||
const SYMBOL_EXTENDED_VALIDATION_RULES = Symbol('SYMBOL_EXTENDED_VALIDATION_RULES'); | ||
const useExtendedValidation = (options) => { | ||
@@ -15,3 +16,12 @@ let schemaTypeInfo; | ||
}, | ||
onParse({ context, extendContext }) { | ||
var _a, _b; | ||
const rules = (_b = (_a = context) === null || _a === void 0 ? void 0 : _a[SYMBOL_EXTENDED_VALIDATION_RULES]) !== null && _b !== void 0 ? _b : []; | ||
rules.push(...options.rules); | ||
extendContext({ | ||
[SYMBOL_EXTENDED_VALIDATION_RULES]: rules, | ||
}); | ||
}, | ||
onExecute({ args, setResultAndStopExecution }) { | ||
const rules = args.contextValue[SYMBOL_EXTENDED_VALIDATION_RULES]; | ||
const errors = []; | ||
@@ -22,9 +32,9 @@ const typeInfo = schemaTypeInfo || new graphql.TypeInfo(args.schema); | ||
}); | ||
const visitor = graphql.visitInParallel(options.rules.map(rule => rule(validationContext, args))); | ||
const visitor = graphql.visitInParallel(rules.map(rule => rule(validationContext, args))); | ||
graphql.visit(args.document, graphql.visitWithTypeInfo(typeInfo, visitor)); | ||
for (const rule of options.rules) { | ||
for (const rule of rules) { | ||
rule(validationContext, args); | ||
} | ||
if (errors.length > 0) { | ||
setResultAndStopExecution({ | ||
return setResultAndStopExecution({ | ||
data: null, | ||
@@ -31,0 +41,0 @@ errors, |
{ | ||
"name": "@envelop/extended-validation", | ||
"version": "0.2.0", | ||
"version": "0.2.1-alpha-81eaa39.0", | ||
"sideEffects": false, | ||
@@ -5,0 +5,0 @@ "peerDependencies": { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
38132
257
0