@envelop/extended-validation 1.9.0 → 1.9.1-alpha-20220901205925-b1fd44a9

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/README.md CHANGED
@@ -17,9 +17,15 @@ yarn add @envelop/extended-validation
17
17
  Then, use the plugin with your validation rules:
18
18
 
19
19
  ```ts
20
+ import { parse, validate, execute, subscribe } from 'graphql'
21
+ import { envelop } from '@envelop/core'
20
22
  import { useExtendedValidation } from '@envelop/extended-validation'
21
23
 
22
- const getEnveloped = evelop({
24
+ const getEnveloped = envelop({
25
+ parse,
26
+ validate,
27
+ execute,
28
+ subscribe,
23
29
  plugins: [
24
30
  useExtendedValidation({
25
31
  rules: [
package/cjs/plugin.js CHANGED
@@ -33,7 +33,6 @@ const useExtendedValidation = (options) => {
33
33
  exports.useExtendedValidation = useExtendedValidation;
34
34
  function buildHandler(name, getTypeInfo, onValidationFailed) {
35
35
  return function handler({ args, setResultAndStopExecution, }) {
36
- var _a;
37
36
  // We hook into onExecute/onSubscribe even though this is a validation pattern. The reasoning behind
38
37
  // it is that hooking right after validation and before execution has started is the
39
38
  // same as hooking into the validation step. The benefit of this approach is that
@@ -49,7 +48,7 @@ function buildHandler(name, getTypeInfo, onValidationFailed) {
49
48
  if (validationRulesContext.rules.length !== 0) {
50
49
  const errors = [];
51
50
  // We replicate the default validation step manually before execution starts.
52
- const typeInfo = (_a = getTypeInfo()) !== null && _a !== void 0 ? _a : new graphql_1.TypeInfo(args.schema);
51
+ const typeInfo = getTypeInfo() ?? new graphql_1.TypeInfo(args.schema);
53
52
  const validationContext = new graphql_1.ValidationContext(args.schema, args.document, typeInfo, e => {
54
53
  errors.push(e);
55
54
  });
@@ -10,14 +10,13 @@ exports.ONE_OF_DIRECTIVE_SDL = `
10
10
  const OneOfInputObjectsRule = (validationContext, executionArgs) => {
11
11
  return {
12
12
  Field: node => {
13
- var _a, _b;
14
- if ((_a = node.arguments) === null || _a === void 0 ? void 0 : _a.length) {
13
+ if (node.arguments?.length) {
15
14
  const fieldType = validationContext.getFieldDef();
16
15
  if (!fieldType) {
17
16
  return;
18
17
  }
19
18
  const values = (0, utils_1.getArgumentValues)(fieldType, node, executionArgs.variableValues || undefined);
20
- const isOneOfFieldType = ((_b = fieldType.extensions) === null || _b === void 0 ? void 0 : _b.oneOf) || (fieldType.astNode && (0, common_js_1.getDirectiveFromAstNode)(fieldType.astNode, 'oneOf'));
19
+ const isOneOfFieldType = fieldType.extensions?.oneOf || (fieldType.astNode && (0, common_js_1.getDirectiveFromAstNode)(fieldType.astNode, 'oneOf'));
21
20
  if (isOneOfFieldType && Object.keys(values).length !== 1) {
22
21
  validationContext.reportError(new graphql_1.GraphQLError(`Exactly one key must be specified for input for field "${fieldType.type.toString()}.${node.name.value}"`, [node]));
23
22
  }
@@ -39,7 +38,6 @@ function getNonNullType(ttype) {
39
38
  return ttype;
40
39
  }
41
40
  function traverseVariables(validationContext, arg, graphqlType, currentValue) {
42
- var _a;
43
41
  // if the current value is empty we don't need to traverse deeper
44
42
  // if it shouldn't be empty, the "original" validation phase should complain.
45
43
  if (currentValue == null) {
@@ -61,7 +59,7 @@ function traverseVariables(validationContext, arg, graphqlType, currentValue) {
61
59
  return;
62
60
  }
63
61
  const inputType = (0, graphql_1.getNamedType)(graphqlType);
64
- const isOneOfInputType = ((_a = inputType.extensions) === null || _a === void 0 ? void 0 : _a.oneOf) || (inputType.astNode && (0, common_js_1.getDirectiveFromAstNode)(inputType.astNode, 'oneOf'));
62
+ const isOneOfInputType = inputType.extensions?.oneOf || (inputType.astNode && (0, common_js_1.getDirectiveFromAstNode)(inputType.astNode, 'oneOf'));
65
63
  if (isOneOfInputType && Object.keys(currentValue).length !== 1) {
66
64
  validationContext.reportError(new graphql_1.GraphQLError(`Exactly one key must be specified for input type "${inputType.name}"`, [arg]));
67
65
  }
package/esm/plugin.js CHANGED
@@ -29,7 +29,6 @@ export const useExtendedValidation = (options) => {
29
29
  };
30
30
  function buildHandler(name, getTypeInfo, onValidationFailed) {
31
31
  return function handler({ args, setResultAndStopExecution, }) {
32
- var _a;
33
32
  // We hook into onExecute/onSubscribe even though this is a validation pattern. The reasoning behind
34
33
  // it is that hooking right after validation and before execution has started is the
35
34
  // same as hooking into the validation step. The benefit of this approach is that
@@ -45,7 +44,7 @@ function buildHandler(name, getTypeInfo, onValidationFailed) {
45
44
  if (validationRulesContext.rules.length !== 0) {
46
45
  const errors = [];
47
46
  // We replicate the default validation step manually before execution starts.
48
- const typeInfo = (_a = getTypeInfo()) !== null && _a !== void 0 ? _a : new TypeInfo(args.schema);
47
+ const typeInfo = getTypeInfo() ?? new TypeInfo(args.schema);
49
48
  const validationContext = new ValidationContext(args.schema, args.document, typeInfo, e => {
50
49
  errors.push(e);
51
50
  });
@@ -7,14 +7,13 @@ export const ONE_OF_DIRECTIVE_SDL = /* GraphQL */ `
7
7
  export const OneOfInputObjectsRule = (validationContext, executionArgs) => {
8
8
  return {
9
9
  Field: node => {
10
- var _a, _b;
11
- if ((_a = node.arguments) === null || _a === void 0 ? void 0 : _a.length) {
10
+ if (node.arguments?.length) {
12
11
  const fieldType = validationContext.getFieldDef();
13
12
  if (!fieldType) {
14
13
  return;
15
14
  }
16
15
  const values = getArgumentValues(fieldType, node, executionArgs.variableValues || undefined);
17
- const isOneOfFieldType = ((_b = fieldType.extensions) === null || _b === void 0 ? void 0 : _b.oneOf) || (fieldType.astNode && getDirectiveFromAstNode(fieldType.astNode, 'oneOf'));
16
+ const isOneOfFieldType = fieldType.extensions?.oneOf || (fieldType.astNode && getDirectiveFromAstNode(fieldType.astNode, 'oneOf'));
18
17
  if (isOneOfFieldType && Object.keys(values).length !== 1) {
19
18
  validationContext.reportError(new GraphQLError(`Exactly one key must be specified for input for field "${fieldType.type.toString()}.${node.name.value}"`, [node]));
20
19
  }
@@ -35,7 +34,6 @@ function getNonNullType(ttype) {
35
34
  return ttype;
36
35
  }
37
36
  function traverseVariables(validationContext, arg, graphqlType, currentValue) {
38
- var _a;
39
37
  // if the current value is empty we don't need to traverse deeper
40
38
  // if it shouldn't be empty, the "original" validation phase should complain.
41
39
  if (currentValue == null) {
@@ -57,7 +55,7 @@ function traverseVariables(validationContext, arg, graphqlType, currentValue) {
57
55
  return;
58
56
  }
59
57
  const inputType = getNamedType(graphqlType);
60
- const isOneOfInputType = ((_a = inputType.extensions) === null || _a === void 0 ? void 0 : _a.oneOf) || (inputType.astNode && getDirectiveFromAstNode(inputType.astNode, 'oneOf'));
58
+ const isOneOfInputType = inputType.extensions?.oneOf || (inputType.astNode && getDirectiveFromAstNode(inputType.astNode, 'oneOf'));
61
59
  if (isOneOfInputType && Object.keys(currentValue).length !== 1) {
62
60
  validationContext.reportError(new GraphQLError(`Exactly one key must be specified for input type "${inputType.name}"`, [arg]));
63
61
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/extended-validation",
3
- "version": "1.9.0",
3
+ "version": "1.9.1-alpha-20220901205925-b1fd44a9",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "^2.6.0",
6
+ "@envelop/core": "2.6.1-alpha-20220901205925-b1fd44a9",
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "dependencies": {