@envelop/core 2.2.0-alpha-0de750a.0 → 2.2.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/index.js CHANGED
@@ -1182,7 +1182,7 @@ const useMaskedErrors = (opts) => {
1182
1182
  const isDev = (_b = opts === null || opts === void 0 ? void 0 : opts.isDev) !== null && _b !== void 0 ? _b : (typeof process !== 'undefined' ? process.env['NODE_ENV'] === 'development' : false);
1183
1183
  const handleResult = makeHandleResult$2(format, message, isDev);
1184
1184
  return {
1185
- onParse: (opts === null || opts === void 0 ? void 0 : opts.onParse) === true
1185
+ onParse: (opts === null || opts === void 0 ? void 0 : opts.handleParseErrors) === true
1186
1186
  ? function onParse() {
1187
1187
  return function onParseEnd({ result, replaceParseResult }) {
1188
1188
  if (result instanceof Error) {
@@ -1191,7 +1191,7 @@ const useMaskedErrors = (opts) => {
1191
1191
  };
1192
1192
  }
1193
1193
  : undefined,
1194
- onValidate: (opts === null || opts === void 0 ? void 0 : opts.onValidate) === true
1194
+ onValidate: (opts === null || opts === void 0 ? void 0 : opts.handleValidationErrors) === true
1195
1195
  ? function onValidate() {
1196
1196
  return function onValidateEnd({ valid, result, setResult }) {
1197
1197
  if (valid === false) {
@@ -1225,12 +1225,15 @@ const useMaskedErrors = (opts) => {
1225
1225
  };
1226
1226
  };
1227
1227
 
1228
- const OnNonIntrospectionFieldReachedValidationRule = (onNonIntrospectionField) => () => {
1228
+ const OnNonIntrospectionFieldReachedValidationRule = (onNonIntrospectionField) => ctx => {
1229
+ const rootQueryType = ctx.getSchema().getQueryType();
1229
1230
  return {
1230
1231
  Field(field) {
1231
- if (!field.name.value.startsWith('__')) {
1232
+ if (ctx.getParentType() === rootQueryType && !field.name.value.startsWith('__')) {
1232
1233
  onNonIntrospectionField();
1234
+ return graphql.BREAK;
1233
1235
  }
1236
+ return undefined;
1234
1237
  },
1235
1238
  };
1236
1239
  };
package/index.mjs CHANGED
@@ -1178,7 +1178,7 @@ const useMaskedErrors = (opts) => {
1178
1178
  const isDev = (_b = opts === null || opts === void 0 ? void 0 : opts.isDev) !== null && _b !== void 0 ? _b : (typeof process !== 'undefined' ? process.env['NODE_ENV'] === 'development' : false);
1179
1179
  const handleResult = makeHandleResult$2(format, message, isDev);
1180
1180
  return {
1181
- onParse: (opts === null || opts === void 0 ? void 0 : opts.onParse) === true
1181
+ onParse: (opts === null || opts === void 0 ? void 0 : opts.handleParseErrors) === true
1182
1182
  ? function onParse() {
1183
1183
  return function onParseEnd({ result, replaceParseResult }) {
1184
1184
  if (result instanceof Error) {
@@ -1187,7 +1187,7 @@ const useMaskedErrors = (opts) => {
1187
1187
  };
1188
1188
  }
1189
1189
  : undefined,
1190
- onValidate: (opts === null || opts === void 0 ? void 0 : opts.onValidate) === true
1190
+ onValidate: (opts === null || opts === void 0 ? void 0 : opts.handleValidationErrors) === true
1191
1191
  ? function onValidate() {
1192
1192
  return function onValidateEnd({ valid, result, setResult }) {
1193
1193
  if (valid === false) {
@@ -1221,12 +1221,15 @@ const useMaskedErrors = (opts) => {
1221
1221
  };
1222
1222
  };
1223
1223
 
1224
- const OnNonIntrospectionFieldReachedValidationRule = (onNonIntrospectionField) => () => {
1224
+ const OnNonIntrospectionFieldReachedValidationRule = (onNonIntrospectionField) => ctx => {
1225
+ const rootQueryType = ctx.getSchema().getQueryType();
1225
1226
  return {
1226
1227
  Field(field) {
1227
- if (!field.name.value.startsWith('__')) {
1228
+ if (ctx.getParentType() === rootQueryType && !field.name.value.startsWith('__')) {
1228
1229
  onNonIntrospectionField();
1230
+ return BREAK;
1229
1231
  }
1232
+ return undefined;
1230
1233
  },
1231
1234
  };
1232
1235
  };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@envelop/core",
3
- "version": "2.2.0-alpha-0de750a.0",
3
+ "version": "2.2.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
7
7
  },
8
8
  "dependencies": {
9
- "@envelop/types": "2.1.0-alpha-0de750a.0"
9
+ "@envelop/types": "2.1.0"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
@@ -17,14 +17,23 @@ export declare type UseMaskedErrorsOpts = {
17
17
  */
18
18
  isDev?: boolean;
19
19
  /**
20
- * Whether parse errors should be masked.
20
+ * Whether parse errors should be processed by this plugin.
21
+ * In general it is not recommend to set this flag to `true`
22
+ * as a `parse` error contains useful information for debugging a GraphQL operation.
23
+ * A `parse` error never contains any sensitive information.
21
24
  * @default false
22
25
  */
23
- onParse?: boolean;
26
+ handleParseErrors?: boolean;
24
27
  /**
25
- * Whether validation errors should be masked.
28
+ * Whether validation errors should processed by this plugin.
29
+ * In general we recommend against setting this flag to `true`
30
+ * as a `validate` error contains useful information for debugging a GraphQL operation.
31
+ * A `validate` error contains "did you mean x" suggestions that make it easier
32
+ * to reverse-introspect a GraphQL schema whose introspection capabilities got disabled.
33
+ * Instead of disabling introspection and masking validation errors, using persisted operations
34
+ * is a safer solution for avoiding the execution of unwanted/arbitrary operations.
26
35
  * @default false
27
36
  */
28
- onValidate?: boolean;
37
+ handleValidationErrors?: boolean;
29
38
  };
30
39
  export declare const useMaskedErrors: (opts?: UseMaskedErrorsOpts | undefined) => Plugin;