@graphql-tools/utils 9.1.1 → 9.1.2-alpha-20221114133606-dae9ff99

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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getDirective = exports.getDirectives = exports.getDirectiveInExtensions = exports.getDirectivesInExtensions = void 0;
4
- const getArgumentValues_js_1 = require("./getArgumentValues.js");
4
+ const graphql_1 = require("graphql");
5
5
  function getDirectivesInExtensions(node, pathToDirectivesInExtensions = ['directives']) {
6
6
  return pathToDirectivesInExtensions.reduce((acc, pathSegment) => (acc == null ? acc : acc[pathSegment]), node === null || node === void 0 ? void 0 : node.extensions);
7
7
  }
@@ -61,7 +61,7 @@ function getDirectives(schema, node, pathToDirectivesInExtensions = ['directives
61
61
  for (const directiveNode of astNode.directives) {
62
62
  const schemaDirective = schemaDirectiveMap[directiveNode.name.value];
63
63
  if (schemaDirective) {
64
- result.push({ name: directiveNode.name.value, args: (0, getArgumentValues_js_1.getArgumentValues)(schemaDirective, directiveNode) });
64
+ result.push({ name: directiveNode.name.value, args: (0, graphql_1.getArgumentValues)(schemaDirective, directiveNode) });
65
65
  }
66
66
  }
67
67
  }
@@ -90,7 +90,7 @@ function getDirective(schema, node, directiveName, pathToDirectivesInExtensions
90
90
  if (astNode.directives) {
91
91
  for (const directiveNode of astNode.directives) {
92
92
  if (directiveNode.name.value === directiveName) {
93
- result.push((0, getArgumentValues_js_1.getArgumentValues)(schemaDirective, directiveNode));
93
+ result.push((0, graphql_1.getArgumentValues)(schemaDirective, directiveNode));
94
94
  }
95
95
  }
96
96
  }
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getArgumentValues = void 0;
4
- const jsutils_js_1 = require("./jsutils.js");
5
4
  const graphql_1 = require("graphql");
6
- const errors_js_1 = require("./errors.js");
7
- const inspect_js_1 = require("./inspect.js");
8
5
  /**
9
6
  * Prepares an object map of argument values given a list of argument
10
7
  * definitions and list of argument AST nodes.
@@ -14,60 +11,6 @@ const inspect_js_1 = require("./inspect.js");
14
11
  * Object prototype.
15
12
  */
16
13
  function getArgumentValues(def, node, variableValues = {}) {
17
- var _a;
18
- const coercedValues = {};
19
- const argumentNodes = (_a = node.arguments) !== null && _a !== void 0 ? _a : [];
20
- const argNodeMap = argumentNodes.reduce((prev, arg) => ({
21
- ...prev,
22
- [arg.name.value]: arg,
23
- }), {});
24
- for (const { name, type: argType, defaultValue } of def.args) {
25
- const argumentNode = argNodeMap[name];
26
- if (!argumentNode) {
27
- if (defaultValue !== undefined) {
28
- coercedValues[name] = defaultValue;
29
- }
30
- else if ((0, graphql_1.isNonNullType)(argType)) {
31
- throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" of required type "${(0, inspect_js_1.inspect)(argType)}" ` + 'was not provided.', {
32
- nodes: [node],
33
- });
34
- }
35
- continue;
36
- }
37
- const valueNode = argumentNode.value;
38
- let isNull = valueNode.kind === graphql_1.Kind.NULL;
39
- if (valueNode.kind === graphql_1.Kind.VARIABLE) {
40
- const variableName = valueNode.name.value;
41
- if (variableValues == null || !(0, jsutils_js_1.hasOwnProperty)(variableValues, variableName)) {
42
- if (defaultValue !== undefined) {
43
- coercedValues[name] = defaultValue;
44
- }
45
- else if ((0, graphql_1.isNonNullType)(argType)) {
46
- throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" of required type "${(0, inspect_js_1.inspect)(argType)}" ` +
47
- `was provided the variable "$${variableName}" which was not provided a runtime value.`, {
48
- nodes: [valueNode],
49
- });
50
- }
51
- continue;
52
- }
53
- isNull = variableValues[variableName] == null;
54
- }
55
- if (isNull && (0, graphql_1.isNonNullType)(argType)) {
56
- throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" of non-null type "${(0, inspect_js_1.inspect)(argType)}" ` + 'must not be null.', {
57
- nodes: [valueNode],
58
- });
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
- });
68
- }
69
- coercedValues[name] = coercedValue;
70
- }
71
- return coercedValues;
14
+ return (0, graphql_1.getArgumentValues)(def, node, variableValues);
72
15
  }
73
16
  exports.getArgumentValues = getArgumentValues;
@@ -1,4 +1,4 @@
1
- import { getArgumentValues } from './getArgumentValues.js';
1
+ import { getArgumentValues, } from 'graphql';
2
2
  export function getDirectivesInExtensions(node, pathToDirectivesInExtensions = ['directives']) {
3
3
  return pathToDirectivesInExtensions.reduce((acc, pathSegment) => (acc == null ? acc : acc[pathSegment]), node === null || node === void 0 ? void 0 : node.extensions);
4
4
  }
@@ -1,7 +1,4 @@
1
- import { hasOwnProperty } from './jsutils.js';
2
- import { valueFromAST, isNonNullType, Kind, print, } from 'graphql';
3
- import { createGraphQLError } from './errors.js';
4
- import { inspect } from './inspect.js';
1
+ import { getArgumentValues as gqljsGetArgumentValues } from 'graphql';
5
2
  /**
6
3
  * Prepares an object map of argument values given a list of argument
7
4
  * definitions and list of argument AST nodes.
@@ -11,59 +8,5 @@ import { inspect } from './inspect.js';
11
8
  * Object prototype.
12
9
  */
13
10
  export function getArgumentValues(def, node, variableValues = {}) {
14
- var _a;
15
- const coercedValues = {};
16
- const argumentNodes = (_a = node.arguments) !== null && _a !== void 0 ? _a : [];
17
- const argNodeMap = argumentNodes.reduce((prev, arg) => ({
18
- ...prev,
19
- [arg.name.value]: arg,
20
- }), {});
21
- for (const { name, type: argType, defaultValue } of def.args) {
22
- const argumentNode = argNodeMap[name];
23
- if (!argumentNode) {
24
- if (defaultValue !== undefined) {
25
- coercedValues[name] = defaultValue;
26
- }
27
- else if (isNonNullType(argType)) {
28
- throw createGraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` + 'was not provided.', {
29
- nodes: [node],
30
- });
31
- }
32
- continue;
33
- }
34
- const valueNode = argumentNode.value;
35
- let isNull = valueNode.kind === Kind.NULL;
36
- if (valueNode.kind === Kind.VARIABLE) {
37
- const variableName = valueNode.name.value;
38
- if (variableValues == null || !hasOwnProperty(variableValues, variableName)) {
39
- if (defaultValue !== undefined) {
40
- coercedValues[name] = defaultValue;
41
- }
42
- else if (isNonNullType(argType)) {
43
- throw createGraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` +
44
- `was provided the variable "$${variableName}" which was not provided a runtime value.`, {
45
- nodes: [valueNode],
46
- });
47
- }
48
- continue;
49
- }
50
- isNull = variableValues[variableName] == null;
51
- }
52
- if (isNull && isNonNullType(argType)) {
53
- throw createGraphQLError(`Argument "${name}" of non-null type "${inspect(argType)}" ` + 'must not be null.', {
54
- nodes: [valueNode],
55
- });
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
- });
65
- }
66
- coercedValues[name] = coercedValue;
67
- }
68
- return coercedValues;
11
+ return gqljsGetArgumentValues(def, node, variableValues);
69
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils",
3
- "version": "9.1.1",
3
+ "version": "9.1.2-alpha-20221114133606-dae9ff99",
4
4
  "description": "Common package containing utils and types for GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -1,4 +1,4 @@
1
- import { GraphQLField, GraphQLDirective, DirectiveNode, FieldNode } from 'graphql';
1
+ import type { GraphQLField, GraphQLDirective, FieldNode, DirectiveNode } from 'graphql';
2
2
  /**
3
3
  * Prepares an object map of argument values given a list of argument
4
4
  * definitions and list of argument AST nodes.
@@ -1,4 +1,4 @@
1
- import { GraphQLField, GraphQLDirective, DirectiveNode, FieldNode } from 'graphql';
1
+ import type { GraphQLField, GraphQLDirective, FieldNode, DirectiveNode } from 'graphql';
2
2
  /**
3
3
  * Prepares an object map of argument values given a list of argument
4
4
  * definitions and list of argument AST nodes.