@envelop/extended-validation 6.0.0 → 6.1.0-alpha-20251028153726-659ec6d34ae34740d8e44926019c7038c1a3ae61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/plugin.js CHANGED
@@ -28,12 +28,12 @@ const useExtendedValidation = (options) => {
28
28
  }
29
29
  validationRulesContext.rules.push(...options.rules);
30
30
  },
31
- onSubscribe: buildHandler('subscribe', getTypeInfo, options.onValidationFailed, options.rejectOnErrors !== false),
32
- onExecute: buildHandler('execute', getTypeInfo, options.onValidationFailed, options.rejectOnErrors !== false),
31
+ onSubscribe: buildHandler('subscribe', getTypeInfo, options.onDocument, options.onValidationFailed, options.rejectOnErrors !== false),
32
+ onExecute: buildHandler('execute', getTypeInfo, options.onDocument, options.onValidationFailed, options.rejectOnErrors !== false),
33
33
  };
34
34
  };
35
35
  exports.useExtendedValidation = useExtendedValidation;
36
- function buildHandler(name, getTypeInfo, onValidationFailed, rejectOnErrors = true) {
36
+ function buildHandler(name, getTypeInfo, onDocument, onValidationFailed, rejectOnErrors = true) {
37
37
  return function handler({ args, setResultAndStopExecution, }) {
38
38
  // We hook into onExecute/onSubscribe even though this is a validation pattern. The reasoning behind
39
39
  // it is that hooking right after validation and before execution has started is the
@@ -56,6 +56,9 @@ function buildHandler(name, getTypeInfo, onValidationFailed, rejectOnErrors = tr
56
56
  });
57
57
  const visitor = (0, graphql_1.visitInParallel)(validationRulesContext.rules.map(rule => rule(validationContext, args)));
58
58
  args.document = (0, graphql_1.visit)(args.document, (0, graphql_1.visitWithTypeInfo)(typeInfo, visitor));
59
+ if (onDocument) {
60
+ args.document = onDocument(args.document);
61
+ }
59
62
  if (errors.length > 0) {
60
63
  if (rejectOnErrors) {
61
64
  let result = {
package/esm/plugin.js CHANGED
@@ -25,11 +25,11 @@ export const useExtendedValidation = (options) => {
25
25
  }
26
26
  validationRulesContext.rules.push(...options.rules);
27
27
  },
28
- onSubscribe: buildHandler('subscribe', getTypeInfo, options.onValidationFailed, options.rejectOnErrors !== false),
29
- onExecute: buildHandler('execute', getTypeInfo, options.onValidationFailed, options.rejectOnErrors !== false),
28
+ onSubscribe: buildHandler('subscribe', getTypeInfo, options.onDocument, options.onValidationFailed, options.rejectOnErrors !== false),
29
+ onExecute: buildHandler('execute', getTypeInfo, options.onDocument, options.onValidationFailed, options.rejectOnErrors !== false),
30
30
  };
31
31
  };
32
- function buildHandler(name, getTypeInfo, onValidationFailed, rejectOnErrors = true) {
32
+ function buildHandler(name, getTypeInfo, onDocument, onValidationFailed, rejectOnErrors = true) {
33
33
  return function handler({ args, setResultAndStopExecution, }) {
34
34
  // We hook into onExecute/onSubscribe even though this is a validation pattern. The reasoning behind
35
35
  // it is that hooking right after validation and before execution has started is the
@@ -52,6 +52,9 @@ function buildHandler(name, getTypeInfo, onValidationFailed, rejectOnErrors = tr
52
52
  });
53
53
  const visitor = visitInParallel(validationRulesContext.rules.map(rule => rule(validationContext, args)));
54
54
  args.document = visit(args.document, visitWithTypeInfo(typeInfo, visitor));
55
+ if (onDocument) {
56
+ args.document = onDocument(args.document);
57
+ }
55
58
  if (errors.length > 0) {
56
59
  if (rejectOnErrors) {
57
60
  let result = {
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@envelop/extended-validation",
3
- "version": "6.0.0",
3
+ "version": "6.1.0-alpha-20251028153726-659ec6d34ae34740d8e44926019c7038c1a3ae61",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
7
- "@envelop/core": "^5.3.0"
7
+ "@envelop/core": "^5.3.2"
8
8
  },
9
9
  "dependencies": {
10
10
  "@graphql-tools/utils": "^10.0.0",
@@ -1,4 +1,4 @@
1
- import { ExecutionArgs, ExecutionResult } from 'graphql';
1
+ import { DocumentNode, ExecutionArgs, ExecutionResult } from 'graphql';
2
2
  import { Plugin } from '@envelop/core';
3
3
  import { ExtendedValidationRule } from './common.cjs';
4
4
  declare const symbolExtendedValidationRules: unique symbol;
@@ -13,6 +13,10 @@ type OnValidationFailedCallback = (params: {
13
13
  }) => void;
14
14
  export declare const useExtendedValidation: <PluginContext extends Record<string, any> = {}>(options: {
15
15
  rules: Array<ExtendedValidationRule>;
16
+ /**
17
+ * Callback that is invoked when the document is assembled by the visitor.
18
+ */
19
+ onDocument?: (document: DocumentNode) => DocumentNode;
16
20
  /**
17
21
  * Callback that is invoked if the extended validation yields any errors.
18
22
  */
@@ -1,4 +1,4 @@
1
- import { ExecutionArgs, ExecutionResult } from 'graphql';
1
+ import { DocumentNode, ExecutionArgs, ExecutionResult } from 'graphql';
2
2
  import { Plugin } from '@envelop/core';
3
3
  import { ExtendedValidationRule } from './common.js';
4
4
  declare const symbolExtendedValidationRules: unique symbol;
@@ -13,6 +13,10 @@ type OnValidationFailedCallback = (params: {
13
13
  }) => void;
14
14
  export declare const useExtendedValidation: <PluginContext extends Record<string, any> = {}>(options: {
15
15
  rules: Array<ExtendedValidationRule>;
16
+ /**
17
+ * Callback that is invoked when the document is assembled by the visitor.
18
+ */
19
+ onDocument?: (document: DocumentNode) => DocumentNode;
16
20
  /**
17
21
  * Callback that is invoked if the extended validation yields any errors.
18
22
  */