@envelop/extended-validation 1.7.0 → 1.7.1-alpha-72027859.0

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,12 +17,14 @@ yarn add @envelop/extended-validation
17
17
  Then, use the plugin with your validation rules:
18
18
 
19
19
  ```ts
20
- import { useExtendedValidation } from '@envelop/extended-validation';
20
+ import { useExtendedValidation } from '@envelop/extended-validation'
21
21
 
22
22
  const getEnveloped = evelop({
23
23
  plugins: [
24
24
  useExtendedValidation({
25
- rules: [ ... ] // your rules here
25
+ rules: [
26
+ /* ... your rules here */
27
+ ]
26
28
  })
27
29
  ]
28
30
  })
@@ -33,7 +35,7 @@ To create your custom rules, implement the `ExtendedValidationRule` interface an
33
35
  For example:
34
36
 
35
37
  ```ts
36
- import { ExtendedValidationRule } from '@envelop/extended-validation';
38
+ import { ExtendedValidationRule } from '@envelop/extended-validation'
37
39
 
38
40
  export const MyRule: ExtendedValidationRule = (validationContext, executionArgs) => {
39
41
  return {
@@ -41,9 +43,9 @@ export const MyRule: ExtendedValidationRule = (validationContext, executionArgs)
41
43
  // This will run for every executed Query/Mutation/Subscription
42
44
  // And now you also have access to the execution params like variables, context and so on.
43
45
  // If you wish to report an error, use validationContext.reportError or throw an exception.
44
- },
45
- };
46
- };
46
+ }
47
+ }
48
+ }
47
49
  ```
48
50
 
49
51
  ## Built-in Rules
@@ -57,15 +59,15 @@ You can use union inputs either via a the SDL flow, by annotating types and fiel
57
59
  First, make sure to add that rule to your plugin usage:
58
60
 
59
61
  ```ts
60
- import { useExtendedValidation, OneOfInputObjectsRule } from '@envelop/extended-validation';
62
+ import { useExtendedValidation, OneOfInputObjectsRule } from '@envelop/extended-validation'
61
63
 
62
64
  const getEnveloped = evelop({
63
65
  plugins: [
64
66
  useExtendedValidation({
65
- rules: [OneOfInputObjectsRule],
66
- }),
67
- ],
68
- });
67
+ rules: [OneOfInputObjectsRule]
68
+ })
69
+ ]
70
+ })
69
71
  ```
70
72
 
71
73
  #### Schema Directive Flow
@@ -99,16 +101,16 @@ const GraphQLFindUserInput = new GraphQLInputObjectType({
99
101
  name: 'FindUserInput',
100
102
  fields: {
101
103
  id: {
102
- type: GraphQLID,
104
+ type: GraphQLID
103
105
  },
104
106
  organizationAndRegistrationNumber: {
105
- type: GraphQLInt,
106
- },
107
+ type: GraphQLInt
108
+ }
107
109
  },
108
110
  extensions: {
109
- oneOf: true,
110
- },
111
- });
111
+ oneOf: true
112
+ }
113
+ })
112
114
 
113
115
  const Query = new GraphQLObjectType({
114
116
  name: 'Query',
@@ -117,19 +119,19 @@ const Query = new GraphQLObjectType({
117
119
  type: GraphQLString,
118
120
  args: {
119
121
  id: {
120
- type: GraphQLID,
122
+ type: GraphQLID
121
123
  },
122
124
  str1: {
123
- type: GraphQLString,
125
+ type: GraphQLString
124
126
  },
125
127
  str2: {
126
- type: GraphQLString,
127
- },
128
+ type: GraphQLString
129
+ }
128
130
  },
129
131
  extensions: {
130
- oneOf: true,
131
- },
132
- },
133
- },
134
- });
132
+ oneOf: true
133
+ }
134
+ }
135
+ }
136
+ })
135
137
  ```
@@ -18,10 +18,8 @@ const OneOfInputObjectsRule = (validationContext, executionArgs) => {
18
18
  }
19
19
  const values = (0, utils_1.getArgumentValues)(fieldType, node, executionArgs.variableValues || undefined);
20
20
  const isOneOfFieldType = ((_b = fieldType.extensions) === null || _b === void 0 ? void 0 : _b.oneOf) || (fieldType.astNode && (0, common_js_1.getDirectiveFromAstNode)(fieldType.astNode, 'oneOf'));
21
- if (isOneOfFieldType) {
22
- if (Object.keys(values).length !== 1) {
23
- validationContext.reportError(new graphql_1.GraphQLError(`Exactly one key must be specified for input for field "${fieldType.type.toString()}.${node.name.value}"`, [node]));
24
- }
21
+ if (isOneOfFieldType && Object.keys(values).length !== 1) {
22
+ validationContext.reportError(new graphql_1.GraphQLError(`Exactly one key must be specified for input for field "${fieldType.type.toString()}.${node.name.value}"`, [node]));
25
23
  }
26
24
  for (const arg of node.arguments) {
27
25
  const argType = fieldType.args.find(typeArg => typeArg.name === arg.name.value);
@@ -64,10 +62,8 @@ function traverseVariables(validationContext, arg, graphqlType, currentValue) {
64
62
  }
65
63
  const inputType = (0, graphql_1.getNamedType)(graphqlType);
66
64
  const isOneOfInputType = ((_a = inputType.extensions) === null || _a === void 0 ? void 0 : _a.oneOf) || (inputType.astNode && (0, common_js_1.getDirectiveFromAstNode)(inputType.astNode, 'oneOf'));
67
- if (isOneOfInputType) {
68
- if (Object.keys(currentValue).length !== 1) {
69
- validationContext.reportError(new graphql_1.GraphQLError(`Exactly one key must be specified for input type "${inputType.name}"`, [arg]));
70
- }
65
+ if (isOneOfInputType && Object.keys(currentValue).length !== 1) {
66
+ validationContext.reportError(new graphql_1.GraphQLError(`Exactly one key must be specified for input type "${inputType.name}"`, [arg]));
71
67
  }
72
68
  if (inputType instanceof graphql_1.GraphQLInputObjectType) {
73
69
  for (const [name, fieldConfig] of Object.entries(inputType.getFields())) {
@@ -15,10 +15,8 @@ export const OneOfInputObjectsRule = (validationContext, executionArgs) => {
15
15
  }
16
16
  const values = getArgumentValues(fieldType, node, executionArgs.variableValues || undefined);
17
17
  const isOneOfFieldType = ((_b = fieldType.extensions) === null || _b === void 0 ? void 0 : _b.oneOf) || (fieldType.astNode && getDirectiveFromAstNode(fieldType.astNode, 'oneOf'));
18
- if (isOneOfFieldType) {
19
- if (Object.keys(values).length !== 1) {
20
- validationContext.reportError(new GraphQLError(`Exactly one key must be specified for input for field "${fieldType.type.toString()}.${node.name.value}"`, [node]));
21
- }
18
+ if (isOneOfFieldType && Object.keys(values).length !== 1) {
19
+ validationContext.reportError(new GraphQLError(`Exactly one key must be specified for input for field "${fieldType.type.toString()}.${node.name.value}"`, [node]));
22
20
  }
23
21
  for (const arg of node.arguments) {
24
22
  const argType = fieldType.args.find(typeArg => typeArg.name === arg.name.value);
@@ -60,10 +58,8 @@ function traverseVariables(validationContext, arg, graphqlType, currentValue) {
60
58
  }
61
59
  const inputType = getNamedType(graphqlType);
62
60
  const isOneOfInputType = ((_a = inputType.extensions) === null || _a === void 0 ? void 0 : _a.oneOf) || (inputType.astNode && getDirectiveFromAstNode(inputType.astNode, 'oneOf'));
63
- if (isOneOfInputType) {
64
- if (Object.keys(currentValue).length !== 1) {
65
- validationContext.reportError(new GraphQLError(`Exactly one key must be specified for input type "${inputType.name}"`, [arg]));
66
- }
61
+ if (isOneOfInputType && Object.keys(currentValue).length !== 1) {
62
+ validationContext.reportError(new GraphQLError(`Exactly one key must be specified for input type "${inputType.name}"`, [arg]));
67
63
  }
68
64
  if (inputType instanceof GraphQLInputObjectType) {
69
65
  for (const [name, fieldConfig] of Object.entries(inputType.getFields())) {
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/extended-validation",
3
- "version": "1.7.0",
3
+ "version": "1.7.1-alpha-72027859.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "^2.4.0",
6
+ "@envelop/core": "2.4.1-alpha-72027859.0",
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "dependencies": {