@graphql-tools/utils 8.12.0 → 8.13.0-alpha-20221025181332-64a4c9e1
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/cjs/Path.js +30 -0
- package/cjs/collectFields.js +1 -1
- package/cjs/getArgumentValues.js +2 -5
- package/cjs/index.js +2 -0
- package/cjs/inspect.js +0 -7
- package/cjs/jsutils.js +29 -0
- package/esm/Path.js +24 -0
- package/esm/collectFields.js +1 -1
- package/esm/getArgumentValues.js +2 -5
- package/esm/index.js +2 -0
- package/esm/inspect.js +0 -7
- package/esm/jsutils.js +21 -0
- package/package.json +1 -1
- package/typings/Path.d.cts +18 -0
- package/typings/Path.d.ts +18 -0
- package/typings/collectFields.d.cts +1 -1
- package/typings/collectFields.d.ts +1 -1
- package/typings/index.d.cts +2 -0
- package/typings/index.d.ts +2 -0
- package/typings/jsutils.d.cts +8 -0
- package/typings/jsutils.d.ts +8 -0
package/cjs/Path.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printPathArray = exports.pathToArray = exports.addPath = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Given a Path and a key, return a new Path containing the new key.
|
|
6
|
+
*/
|
|
7
|
+
function addPath(prev, key, typename) {
|
|
8
|
+
return { prev, key, typename };
|
|
9
|
+
}
|
|
10
|
+
exports.addPath = addPath;
|
|
11
|
+
/**
|
|
12
|
+
* Given a Path, return an Array of the path keys.
|
|
13
|
+
*/
|
|
14
|
+
function pathToArray(path) {
|
|
15
|
+
const flattened = [];
|
|
16
|
+
let curr = path;
|
|
17
|
+
while (curr) {
|
|
18
|
+
flattened.push(curr.key);
|
|
19
|
+
curr = curr.prev;
|
|
20
|
+
}
|
|
21
|
+
return flattened.reverse();
|
|
22
|
+
}
|
|
23
|
+
exports.pathToArray = pathToArray;
|
|
24
|
+
/**
|
|
25
|
+
* Build a string describing the path.
|
|
26
|
+
*/
|
|
27
|
+
function printPathArray(path) {
|
|
28
|
+
return path.map(key => (typeof key === 'number' ? '[' + key.toString() + ']' : '.' + key)).join('');
|
|
29
|
+
}
|
|
30
|
+
exports.printPathArray = printPathArray;
|
package/cjs/collectFields.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.collectSubFields = exports.collectFields = void 0;
|
|
|
4
4
|
const memoize_js_1 = require("./memoize.js");
|
|
5
5
|
const graphql_1 = require("graphql");
|
|
6
6
|
// Taken from GraphQL-JS v16 for backwards compat
|
|
7
|
-
function collectFields(schema, fragments, variableValues, runtimeType, selectionSet, fields, visitedFragmentNames) {
|
|
7
|
+
function collectFields(schema, fragments, variableValues, runtimeType, selectionSet, fields = new Map(), visitedFragmentNames = new Set()) {
|
|
8
8
|
for (const selection of selectionSet.selections) {
|
|
9
9
|
switch (selection.kind) {
|
|
10
10
|
case graphql_1.Kind.FIELD: {
|
package/cjs/getArgumentValues.js
CHANGED
|
@@ -1,6 +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");
|
|
4
5
|
const graphql_1 = require("graphql");
|
|
5
6
|
const errors_js_1 = require("./errors.js");
|
|
6
7
|
const inspect_js_1 = require("./inspect.js");
|
|
@@ -14,10 +15,6 @@ const inspect_js_1 = require("./inspect.js");
|
|
|
14
15
|
*/
|
|
15
16
|
function getArgumentValues(def, node, variableValues = {}) {
|
|
16
17
|
var _a;
|
|
17
|
-
const variableMap = Object.entries(variableValues).reduce((prev, [key, value]) => ({
|
|
18
|
-
...prev,
|
|
19
|
-
[key]: value,
|
|
20
|
-
}), {});
|
|
21
18
|
const coercedValues = {};
|
|
22
19
|
const argumentNodes = (_a = node.arguments) !== null && _a !== void 0 ? _a : [];
|
|
23
20
|
const argNodeMap = argumentNodes.reduce((prev, arg) => ({
|
|
@@ -41,7 +38,7 @@ function getArgumentValues(def, node, variableValues = {}) {
|
|
|
41
38
|
let isNull = valueNode.kind === graphql_1.Kind.NULL;
|
|
42
39
|
if (valueNode.kind === graphql_1.Kind.VARIABLE) {
|
|
43
40
|
const variableName = valueNode.name.value;
|
|
44
|
-
if (variableValues == null ||
|
|
41
|
+
if (variableValues == null || !(0, jsutils_js_1.hasOwnProperty)(variableValues, variableName)) {
|
|
45
42
|
if (defaultValue !== undefined) {
|
|
46
43
|
coercedValues[name] = defaultValue;
|
|
47
44
|
}
|
package/cjs/index.js
CHANGED
|
@@ -53,3 +53,5 @@ tslib_1.__exportStar(require("./memoize.js"), exports);
|
|
|
53
53
|
tslib_1.__exportStar(require("./fixSchemaAst.js"), exports);
|
|
54
54
|
tslib_1.__exportStar(require("./getOperationASTFromRequest.js"), exports);
|
|
55
55
|
tslib_1.__exportStar(require("./extractExtensionsFromSchema.js"), exports);
|
|
56
|
+
tslib_1.__exportStar(require("./Path.js"), exports);
|
|
57
|
+
tslib_1.__exportStar(require("./jsutils.js"), exports);
|
package/cjs/inspect.js
CHANGED
|
@@ -79,17 +79,10 @@ function formatArray(array, seenValues) {
|
|
|
79
79
|
return '[Array]';
|
|
80
80
|
}
|
|
81
81
|
const len = array.length;
|
|
82
|
-
const remaining = array.length;
|
|
83
82
|
const items = [];
|
|
84
83
|
for (let i = 0; i < len; ++i) {
|
|
85
84
|
items.push(formatValue(array[i], seenValues));
|
|
86
85
|
}
|
|
87
|
-
if (remaining === 1) {
|
|
88
|
-
items.push('... 1 more item');
|
|
89
|
-
}
|
|
90
|
-
else if (remaining > 1) {
|
|
91
|
-
items.push(`... ${remaining} more items`);
|
|
92
|
-
}
|
|
93
86
|
return '[' + items.join(', ') + ']';
|
|
94
87
|
}
|
|
95
88
|
function getObjectTag(object) {
|
package/cjs/jsutils.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasOwnProperty = exports.promiseReduce = exports.isPromise = exports.isObjectLike = exports.isIterableObject = void 0;
|
|
4
|
+
function isIterableObject(value) {
|
|
5
|
+
return value != null && typeof value === 'object' && Symbol.iterator in value;
|
|
6
|
+
}
|
|
7
|
+
exports.isIterableObject = isIterableObject;
|
|
8
|
+
function isObjectLike(value) {
|
|
9
|
+
return typeof value === 'object' && value !== null;
|
|
10
|
+
}
|
|
11
|
+
exports.isObjectLike = isObjectLike;
|
|
12
|
+
function isPromise(value) {
|
|
13
|
+
return isObjectLike(value) && typeof value['then'] === 'function';
|
|
14
|
+
}
|
|
15
|
+
exports.isPromise = isPromise;
|
|
16
|
+
function promiseReduce(values, callbackFn, initialValue) {
|
|
17
|
+
let accumulator = initialValue;
|
|
18
|
+
for (const value of values) {
|
|
19
|
+
accumulator = isPromise(accumulator)
|
|
20
|
+
? accumulator.then(resolved => callbackFn(resolved, value))
|
|
21
|
+
: callbackFn(accumulator, value);
|
|
22
|
+
}
|
|
23
|
+
return accumulator;
|
|
24
|
+
}
|
|
25
|
+
exports.promiseReduce = promiseReduce;
|
|
26
|
+
function hasOwnProperty(obj, prop) {
|
|
27
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
28
|
+
}
|
|
29
|
+
exports.hasOwnProperty = hasOwnProperty;
|
package/esm/Path.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given a Path and a key, return a new Path containing the new key.
|
|
3
|
+
*/
|
|
4
|
+
export function addPath(prev, key, typename) {
|
|
5
|
+
return { prev, key, typename };
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Given a Path, return an Array of the path keys.
|
|
9
|
+
*/
|
|
10
|
+
export function pathToArray(path) {
|
|
11
|
+
const flattened = [];
|
|
12
|
+
let curr = path;
|
|
13
|
+
while (curr) {
|
|
14
|
+
flattened.push(curr.key);
|
|
15
|
+
curr = curr.prev;
|
|
16
|
+
}
|
|
17
|
+
return flattened.reverse();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Build a string describing the path.
|
|
21
|
+
*/
|
|
22
|
+
export function printPathArray(path) {
|
|
23
|
+
return path.map(key => (typeof key === 'number' ? '[' + key.toString() + ']' : '.' + key)).join('');
|
|
24
|
+
}
|
package/esm/collectFields.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { memoize5 } from './memoize.js';
|
|
2
2
|
import { Kind, getDirectiveValues, GraphQLSkipDirective, GraphQLIncludeDirective, isAbstractType, typeFromAST, } from 'graphql';
|
|
3
3
|
// Taken from GraphQL-JS v16 for backwards compat
|
|
4
|
-
export function collectFields(schema, fragments, variableValues, runtimeType, selectionSet, fields, visitedFragmentNames) {
|
|
4
|
+
export function collectFields(schema, fragments, variableValues, runtimeType, selectionSet, fields = new Map(), visitedFragmentNames = new Set()) {
|
|
5
5
|
for (const selection of selectionSet.selections) {
|
|
6
6
|
switch (selection.kind) {
|
|
7
7
|
case Kind.FIELD: {
|
package/esm/getArgumentValues.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { hasOwnProperty } from './jsutils.js';
|
|
1
2
|
import { valueFromAST, isNonNullType, Kind, print, } from 'graphql';
|
|
2
3
|
import { createGraphQLError } from './errors.js';
|
|
3
4
|
import { inspect } from './inspect.js';
|
|
@@ -11,10 +12,6 @@ import { inspect } from './inspect.js';
|
|
|
11
12
|
*/
|
|
12
13
|
export function getArgumentValues(def, node, variableValues = {}) {
|
|
13
14
|
var _a;
|
|
14
|
-
const variableMap = Object.entries(variableValues).reduce((prev, [key, value]) => ({
|
|
15
|
-
...prev,
|
|
16
|
-
[key]: value,
|
|
17
|
-
}), {});
|
|
18
15
|
const coercedValues = {};
|
|
19
16
|
const argumentNodes = (_a = node.arguments) !== null && _a !== void 0 ? _a : [];
|
|
20
17
|
const argNodeMap = argumentNodes.reduce((prev, arg) => ({
|
|
@@ -38,7 +35,7 @@ export function getArgumentValues(def, node, variableValues = {}) {
|
|
|
38
35
|
let isNull = valueNode.kind === Kind.NULL;
|
|
39
36
|
if (valueNode.kind === Kind.VARIABLE) {
|
|
40
37
|
const variableName = valueNode.name.value;
|
|
41
|
-
if (variableValues == null ||
|
|
38
|
+
if (variableValues == null || !hasOwnProperty(variableValues, variableName)) {
|
|
42
39
|
if (defaultValue !== undefined) {
|
|
43
40
|
coercedValues[name] = defaultValue;
|
|
44
41
|
}
|
package/esm/index.js
CHANGED
package/esm/inspect.js
CHANGED
|
@@ -75,17 +75,10 @@ function formatArray(array, seenValues) {
|
|
|
75
75
|
return '[Array]';
|
|
76
76
|
}
|
|
77
77
|
const len = array.length;
|
|
78
|
-
const remaining = array.length;
|
|
79
78
|
const items = [];
|
|
80
79
|
for (let i = 0; i < len; ++i) {
|
|
81
80
|
items.push(formatValue(array[i], seenValues));
|
|
82
81
|
}
|
|
83
|
-
if (remaining === 1) {
|
|
84
|
-
items.push('... 1 more item');
|
|
85
|
-
}
|
|
86
|
-
else if (remaining > 1) {
|
|
87
|
-
items.push(`... ${remaining} more items`);
|
|
88
|
-
}
|
|
89
82
|
return '[' + items.join(', ') + ']';
|
|
90
83
|
}
|
|
91
84
|
function getObjectTag(object) {
|
package/esm/jsutils.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function isIterableObject(value) {
|
|
2
|
+
return value != null && typeof value === 'object' && Symbol.iterator in value;
|
|
3
|
+
}
|
|
4
|
+
export function isObjectLike(value) {
|
|
5
|
+
return typeof value === 'object' && value !== null;
|
|
6
|
+
}
|
|
7
|
+
export function isPromise(value) {
|
|
8
|
+
return isObjectLike(value) && typeof value['then'] === 'function';
|
|
9
|
+
}
|
|
10
|
+
export function promiseReduce(values, callbackFn, initialValue) {
|
|
11
|
+
let accumulator = initialValue;
|
|
12
|
+
for (const value of values) {
|
|
13
|
+
accumulator = isPromise(accumulator)
|
|
14
|
+
? accumulator.then(resolved => callbackFn(resolved, value))
|
|
15
|
+
: callbackFn(accumulator, value);
|
|
16
|
+
}
|
|
17
|
+
return accumulator;
|
|
18
|
+
}
|
|
19
|
+
export function hasOwnProperty(obj, prop) {
|
|
20
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Maybe } from './types';
|
|
2
|
+
export interface Path {
|
|
3
|
+
readonly prev: Path | undefined;
|
|
4
|
+
readonly key: string | number;
|
|
5
|
+
readonly typename: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Given a Path and a key, return a new Path containing the new key.
|
|
9
|
+
*/
|
|
10
|
+
export declare function addPath(prev: Readonly<Path> | undefined, key: string | number, typename: string | undefined): Path;
|
|
11
|
+
/**
|
|
12
|
+
* Given a Path, return an Array of the path keys.
|
|
13
|
+
*/
|
|
14
|
+
export declare function pathToArray(path: Maybe<Readonly<Path>>): Array<string | number>;
|
|
15
|
+
/**
|
|
16
|
+
* Build a string describing the path.
|
|
17
|
+
*/
|
|
18
|
+
export declare function printPathArray(path: ReadonlyArray<string | number>): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Maybe } from './types';
|
|
2
|
+
export interface Path {
|
|
3
|
+
readonly prev: Path | undefined;
|
|
4
|
+
readonly key: string | number;
|
|
5
|
+
readonly typename: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Given a Path and a key, return a new Path containing the new key.
|
|
9
|
+
*/
|
|
10
|
+
export declare function addPath(prev: Readonly<Path> | undefined, key: string | number, typename: string | undefined): Path;
|
|
11
|
+
/**
|
|
12
|
+
* Given a Path, return an Array of the path keys.
|
|
13
|
+
*/
|
|
14
|
+
export declare function pathToArray(path: Maybe<Readonly<Path>>): Array<string | number>;
|
|
15
|
+
/**
|
|
16
|
+
* Build a string describing the path.
|
|
17
|
+
*/
|
|
18
|
+
export declare function printPathArray(path: ReadonlyArray<string | number>): string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLSchema, FragmentDefinitionNode, GraphQLObjectType, SelectionSetNode, FieldNode } from 'graphql';
|
|
2
2
|
export declare function collectFields(schema: GraphQLSchema, fragments: Record<string, FragmentDefinitionNode>, variableValues: {
|
|
3
3
|
[variable: string]: unknown;
|
|
4
|
-
}, runtimeType: GraphQLObjectType, selectionSet: SelectionSetNode, fields
|
|
4
|
+
}, runtimeType: GraphQLObjectType, selectionSet: SelectionSetNode, fields?: Map<string, Array<FieldNode>>, visitedFragmentNames?: Set<string>): Map<string, Array<FieldNode>>;
|
|
5
5
|
export declare const collectSubFields: (schema: GraphQLSchema, fragments: Record<string, FragmentDefinitionNode>, variableValues: Record<string, any>, type: GraphQLObjectType, fieldNodes: Array<FieldNode>) => Map<string, Array<FieldNode>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLSchema, FragmentDefinitionNode, GraphQLObjectType, SelectionSetNode, FieldNode } from 'graphql';
|
|
2
2
|
export declare function collectFields(schema: GraphQLSchema, fragments: Record<string, FragmentDefinitionNode>, variableValues: {
|
|
3
3
|
[variable: string]: unknown;
|
|
4
|
-
}, runtimeType: GraphQLObjectType, selectionSet: SelectionSetNode, fields
|
|
4
|
+
}, runtimeType: GraphQLObjectType, selectionSet: SelectionSetNode, fields?: Map<string, Array<FieldNode>>, visitedFragmentNames?: Set<string>): Map<string, Array<FieldNode>>;
|
|
5
5
|
export declare const collectSubFields: (schema: GraphQLSchema, fragments: Record<string, FragmentDefinitionNode>, variableValues: Record<string, any>, type: GraphQLObjectType, fieldNodes: Array<FieldNode>) => Map<string, Array<FieldNode>>;
|
package/typings/index.d.cts
CHANGED
package/typings/index.d.ts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare type PromiseOrValue<T> = Promise<T> | T;
|
|
2
|
+
export declare function isIterableObject(value: unknown): value is Iterable<unknown>;
|
|
3
|
+
export declare function isObjectLike(value: unknown): value is {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
};
|
|
6
|
+
export declare function isPromise<T>(value: unknown): value is Promise<T>;
|
|
7
|
+
export declare function promiseReduce<T, U>(values: Iterable<T>, callbackFn: (accumulator: U, currentValue: T) => PromiseOrValue<U>, initialValue: PromiseOrValue<U>): PromiseOrValue<U>;
|
|
8
|
+
export declare function hasOwnProperty(obj: unknown, prop: string): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare type PromiseOrValue<T> = Promise<T> | T;
|
|
2
|
+
export declare function isIterableObject(value: unknown): value is Iterable<unknown>;
|
|
3
|
+
export declare function isObjectLike(value: unknown): value is {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
};
|
|
6
|
+
export declare function isPromise<T>(value: unknown): value is Promise<T>;
|
|
7
|
+
export declare function promiseReduce<T, U>(values: Iterable<T>, callbackFn: (accumulator: U, currentValue: T) => PromiseOrValue<U>, initialValue: PromiseOrValue<U>): PromiseOrValue<U>;
|
|
8
|
+
export declare function hasOwnProperty(obj: unknown, prop: string): boolean;
|