@graphql-tools/utils 9.0.0 → 9.1.0-alpha-20221107154712-2cdb94c3

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.
@@ -14,7 +14,7 @@ const inspect_js_1 = require("./inspect.js");
14
14
  * Object prototype.
15
15
  */
16
16
  function getArgumentValues(def, node, variableValues = {}) {
17
- var _a;
17
+ var _a, _b, _c, _d;
18
18
  const coercedValues = {};
19
19
  const argumentNodes = (_a = node.arguments) !== null && _a !== void 0 ? _a : [];
20
20
  const argNodeMap = argumentNodes.reduce((prev, arg) => ({
@@ -57,16 +57,43 @@ function getArgumentValues(def, node, variableValues = {}) {
57
57
  nodes: [valueNode],
58
58
  });
59
59
  }
60
- const coercedValue = (0, graphql_1.valueFromAST)(valueNode, argType, variableValues);
61
- if (coercedValue === undefined) {
62
- // Note: ValuesOfCorrectTypeRule validation should catch this before
63
- // execution. This is a runtime check to ensure execution does not
64
- // continue with an invalid argument value.
65
- throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" has invalid value ${(0, graphql_1.print)(valueNode)}.`, {
66
- nodes: [valueNode],
67
- });
60
+ try {
61
+ const coercedValue = (0, graphql_1.valueFromAST)(valueNode, argType, variableValues);
62
+ if (coercedValue === undefined) {
63
+ // Note: ValuesOfCorrectTypeRule validation should catch this before
64
+ // execution. This is a runtime check to ensure execution does not
65
+ // continue with an invalid argument value.
66
+ throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" has invalid value ${(0, graphql_1.print)(valueNode)}.`, {
67
+ nodes: [valueNode],
68
+ });
69
+ }
70
+ coercedValues[name] = coercedValue;
71
+ }
72
+ catch (e) {
73
+ if (e instanceof graphql_1.GraphQLError && ((_c = (_b = e.extensions) === null || _b === void 0 ? void 0 : _b.http) === null || _c === void 0 ? void 0 : _c.status) == null) {
74
+ Object.defineProperty(e, 'extensions', {
75
+ value: {
76
+ ...e.extensions,
77
+ http: {
78
+ ...(_d = e.extensions) === null || _d === void 0 ? void 0 : _d.http,
79
+ status: 400,
80
+ },
81
+ },
82
+ });
83
+ throw e;
84
+ }
85
+ else if (e instanceof TypeError) {
86
+ throw (0, errors_js_1.createGraphQLError)(e.message, {
87
+ nodes: [valueNode],
88
+ extensions: {
89
+ http: {
90
+ status: 400,
91
+ },
92
+ },
93
+ });
94
+ }
95
+ throw e;
68
96
  }
69
- coercedValues[name] = coercedValue;
70
97
  }
71
98
  return coercedValues;
72
99
  }
@@ -1,5 +1,5 @@
1
1
  import { hasOwnProperty } from './jsutils.js';
2
- import { valueFromAST, isNonNullType, Kind, print, } from 'graphql';
2
+ import { valueFromAST, isNonNullType, Kind, print, GraphQLError, } from 'graphql';
3
3
  import { createGraphQLError } from './errors.js';
4
4
  import { inspect } from './inspect.js';
5
5
  /**
@@ -11,7 +11,7 @@ import { inspect } from './inspect.js';
11
11
  * Object prototype.
12
12
  */
13
13
  export function getArgumentValues(def, node, variableValues = {}) {
14
- var _a;
14
+ var _a, _b, _c, _d;
15
15
  const coercedValues = {};
16
16
  const argumentNodes = (_a = node.arguments) !== null && _a !== void 0 ? _a : [];
17
17
  const argNodeMap = argumentNodes.reduce((prev, arg) => ({
@@ -54,16 +54,43 @@ export function getArgumentValues(def, node, variableValues = {}) {
54
54
  nodes: [valueNode],
55
55
  });
56
56
  }
57
- const coercedValue = valueFromAST(valueNode, argType, variableValues);
58
- if (coercedValue === undefined) {
59
- // Note: ValuesOfCorrectTypeRule validation should catch this before
60
- // execution. This is a runtime check to ensure execution does not
61
- // continue with an invalid argument value.
62
- throw createGraphQLError(`Argument "${name}" has invalid value ${print(valueNode)}.`, {
63
- nodes: [valueNode],
64
- });
57
+ try {
58
+ const coercedValue = valueFromAST(valueNode, argType, variableValues);
59
+ if (coercedValue === undefined) {
60
+ // Note: ValuesOfCorrectTypeRule validation should catch this before
61
+ // execution. This is a runtime check to ensure execution does not
62
+ // continue with an invalid argument value.
63
+ throw createGraphQLError(`Argument "${name}" has invalid value ${print(valueNode)}.`, {
64
+ nodes: [valueNode],
65
+ });
66
+ }
67
+ coercedValues[name] = coercedValue;
68
+ }
69
+ catch (e) {
70
+ if (e instanceof GraphQLError && ((_c = (_b = e.extensions) === null || _b === void 0 ? void 0 : _b.http) === null || _c === void 0 ? void 0 : _c.status) == null) {
71
+ Object.defineProperty(e, 'extensions', {
72
+ value: {
73
+ ...e.extensions,
74
+ http: {
75
+ ...(_d = e.extensions) === null || _d === void 0 ? void 0 : _d.http,
76
+ status: 400,
77
+ },
78
+ },
79
+ });
80
+ throw e;
81
+ }
82
+ else if (e instanceof TypeError) {
83
+ throw createGraphQLError(e.message, {
84
+ nodes: [valueNode],
85
+ extensions: {
86
+ http: {
87
+ status: 400,
88
+ },
89
+ },
90
+ });
91
+ }
92
+ throw e;
65
93
  }
66
- coercedValues[name] = coercedValue;
67
94
  }
68
95
  return coercedValues;
69
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils",
3
- "version": "9.0.0",
3
+ "version": "9.1.0-alpha-20221107154712-2cdb94c3",
4
4
  "description": "Common package containing utils and types for GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -15,6 +15,7 @@ export interface ExecutionResult<TData = any, TExtensions = any> {
15
15
  extensions?: TExtensions;
16
16
  label?: string;
17
17
  path?: ReadonlyArray<string | number>;
18
+ items?: TData | null;
18
19
  }
19
20
  export interface ExecutionRequest<TArgs extends Record<string, any> = Record<string, any>, TContext = any, TRootValue = any, TExtensions = Record<string, any>> {
20
21
  document: DocumentNode;
@@ -15,6 +15,7 @@ export interface ExecutionResult<TData = any, TExtensions = any> {
15
15
  extensions?: TExtensions;
16
16
  label?: string;
17
17
  path?: ReadonlyArray<string | number>;
18
+ items?: TData | null;
18
19
  }
19
20
  export interface ExecutionRequest<TArgs extends Record<string, any> = Record<string, any>, TContext = any, TRootValue = any, TExtensions = Record<string, any>> {
20
21
  document: DocumentNode;