@graphql-tools/utils 10.7.2 → 12.0.1

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.
Files changed (89) hide show
  1. package/cjs/astFromValue.js +21 -14
  2. package/cjs/build-operation-for-field.js +13 -3
  3. package/cjs/collectFields.js +4 -3
  4. package/cjs/comments.js +1 -1
  5. package/cjs/defaultValueAstFromType.js +32 -0
  6. package/cjs/descriptionFromObject.js +7 -5
  7. package/cjs/errors.js +30 -4
  8. package/cjs/getArgumentValues.js +23 -15
  9. package/cjs/getDirectiveValues.js +15 -0
  10. package/cjs/heal.js +4 -1
  11. package/cjs/helpers.js +40 -4
  12. package/cjs/index.js +8 -5
  13. package/cjs/jsutils.js +4 -6
  14. package/cjs/mapSchema.js +2 -1
  15. package/cjs/mergeDeep.js +35 -9
  16. package/cjs/mergeIncrementalResult.js +25 -4
  17. package/cjs/observableToAsyncIterable.js +29 -17
  18. package/cjs/print-schema-with-directives.js +23 -17
  19. package/cjs/registerAbortSignalListener.js +5 -1
  20. package/cjs/stub.js +1 -0
  21. package/cjs/updateArgument.js +2 -1
  22. package/cjs/visitResult.js +7 -1
  23. package/esm/astFromValue.js +21 -14
  24. package/esm/build-operation-for-field.js +13 -3
  25. package/esm/collectFields.js +2 -1
  26. package/esm/comments.js +1 -1
  27. package/esm/defaultValueAstFromType.js +28 -0
  28. package/esm/descriptionFromObject.js +7 -5
  29. package/esm/errors.js +29 -6
  30. package/esm/getArgumentValues.js +24 -16
  31. package/esm/getDirectiveValues.js +12 -0
  32. package/esm/heal.js +4 -1
  33. package/esm/helpers.js +39 -4
  34. package/esm/index.js +3 -4
  35. package/esm/jsutils.js +3 -5
  36. package/esm/mapSchema.js +2 -1
  37. package/esm/mergeDeep.js +35 -9
  38. package/esm/mergeIncrementalResult.js +25 -4
  39. package/esm/observableToAsyncIterable.js +28 -16
  40. package/esm/print-schema-with-directives.js +24 -18
  41. package/esm/registerAbortSignalListener.js +5 -1
  42. package/esm/stub.js +1 -0
  43. package/esm/updateArgument.js +2 -1
  44. package/esm/visitResult.js +7 -1
  45. package/package.json +3 -3
  46. package/typings/Interfaces.d.cts +39 -0
  47. package/typings/Interfaces.d.ts +39 -0
  48. package/typings/collectFields.d.cts +5 -6
  49. package/typings/collectFields.d.ts +5 -6
  50. package/typings/defaultValueAstFromType.d.cts +9 -0
  51. package/typings/defaultValueAstFromType.d.ts +9 -0
  52. package/typings/errors.d.cts +19 -1
  53. package/typings/errors.d.ts +19 -1
  54. package/typings/executor.d.cts +4 -7
  55. package/typings/executor.d.ts +4 -7
  56. package/typings/getDirectiveExtensions.d.cts +1 -3
  57. package/typings/getDirectiveExtensions.d.ts +1 -3
  58. package/typings/getDirectiveValues.d.cts +10 -0
  59. package/typings/getDirectiveValues.d.ts +10 -0
  60. package/typings/helpers.d.cts +28 -2
  61. package/typings/helpers.d.ts +28 -2
  62. package/typings/index.d.cts +3 -4
  63. package/typings/index.d.ts +3 -4
  64. package/typings/jsutils.d.cts +2 -2
  65. package/typings/jsutils.d.ts +2 -2
  66. package/typings/mergeDeep.d.cts +1 -1
  67. package/typings/mergeDeep.d.ts +1 -1
  68. package/typings/print-schema-with-directives.d.cts +1 -0
  69. package/typings/print-schema-with-directives.d.ts +1 -0
  70. package/typings/registerAbortSignalListener.d.cts +1 -1
  71. package/typings/registerAbortSignalListener.d.ts +1 -1
  72. package/typings/types.d.cts +25 -1
  73. package/typings/types.d.ts +25 -1
  74. package/cjs/createDeferred.js +0 -15
  75. package/cjs/fakePromise.js +0 -63
  76. package/cjs/map-maybe-promise.js +0 -26
  77. package/cjs/mapAsyncIterator.js +0 -75
  78. package/esm/createDeferred.js +0 -12
  79. package/esm/fakePromise.js +0 -59
  80. package/esm/map-maybe-promise.js +0 -23
  81. package/esm/mapAsyncIterator.js +0 -72
  82. package/typings/createDeferred.d.cts +0 -6
  83. package/typings/createDeferred.d.ts +0 -6
  84. package/typings/fakePromise.d.cts +0 -4
  85. package/typings/fakePromise.d.ts +0 -4
  86. package/typings/map-maybe-promise.d.cts +0 -2
  87. package/typings/map-maybe-promise.d.ts +0 -2
  88. package/typings/mapAsyncIterator.d.cts +0 -6
  89. package/typings/mapAsyncIterator.d.ts +0 -6
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapAsyncIterator = mapAsyncIterator;
4
- const fakePromise_js_1 = require("./fakePromise.js");
5
- const map_maybe_promise_js_1 = require("./map-maybe-promise.js");
6
- /**
7
- * Given an AsyncIterable and a callback function, return an AsyncIterator
8
- * which produces values mapped via calling the callback function.
9
- */
10
- function mapAsyncIterator(iterator, onNext, onError, onEnd) {
11
- if (Symbol.asyncIterator in iterator) {
12
- iterator = iterator[Symbol.asyncIterator]();
13
- }
14
- let $return;
15
- let abruptClose;
16
- let onEndWithValue;
17
- if (onEnd) {
18
- let onEndWithValueResult /** R in onEndWithValue */;
19
- onEndWithValue = value => {
20
- onEndWithValueResult ||= (0, map_maybe_promise_js_1.mapMaybePromise)(onEnd(), () => value);
21
- return onEndWithValueResult;
22
- };
23
- }
24
- if (typeof iterator.return === 'function') {
25
- $return = iterator.return;
26
- abruptClose = (error) => {
27
- const rethrow = () => {
28
- throw error;
29
- };
30
- return $return.call(iterator).then(rethrow, rethrow);
31
- };
32
- }
33
- function mapResult(result) {
34
- if (result.done) {
35
- return onEndWithValue ? onEndWithValue(result) : result;
36
- }
37
- return (0, map_maybe_promise_js_1.mapMaybePromise)(result.value, value => (0, map_maybe_promise_js_1.mapMaybePromise)(onNext(value), iteratorResult, abruptClose));
38
- }
39
- let mapReject;
40
- if (onError) {
41
- let onErrorResult;
42
- // Capture rejectCallback to ensure it cannot be null.
43
- const reject = onError;
44
- mapReject = (error) => {
45
- onErrorResult ||= (0, map_maybe_promise_js_1.mapMaybePromise)(error, error => (0, map_maybe_promise_js_1.mapMaybePromise)(reject(error), iteratorResult, abruptClose));
46
- return onErrorResult;
47
- };
48
- }
49
- return {
50
- next() {
51
- return iterator.next().then(mapResult, mapReject);
52
- },
53
- return() {
54
- const res$ = $return
55
- ? $return.call(iterator).then(mapResult, mapReject)
56
- : (0, fakePromise_js_1.fakePromise)({ value: undefined, done: true });
57
- return onEndWithValue ? res$.then(onEndWithValue) : res$;
58
- },
59
- throw(error) {
60
- if (typeof iterator.throw === 'function') {
61
- return iterator.throw(error).then(mapResult, mapReject);
62
- }
63
- if (abruptClose) {
64
- return abruptClose(error);
65
- }
66
- return (0, fakePromise_js_1.fakeRejectPromise)(error);
67
- },
68
- [Symbol.asyncIterator]() {
69
- return this;
70
- },
71
- };
72
- }
73
- function iteratorResult(value) {
74
- return { value, done: false };
75
- }
@@ -1,12 +0,0 @@
1
- export function createDeferred() {
2
- if (Promise.withResolvers) {
3
- return Promise.withResolvers();
4
- }
5
- let resolve;
6
- let reject;
7
- const promise = new Promise((_resolve, _reject) => {
8
- resolve = _resolve;
9
- reject = _reject;
10
- });
11
- return { promise, resolve, reject };
12
- }
@@ -1,59 +0,0 @@
1
- function isPromise(val) {
2
- return val?.then != null;
3
- }
4
- export function fakeRejectPromise(error) {
5
- if (isPromise(error)) {
6
- return error;
7
- }
8
- return {
9
- then() {
10
- return this;
11
- },
12
- catch(reject) {
13
- if (reject) {
14
- return fakePromise(reject(error));
15
- }
16
- return this;
17
- },
18
- finally(cb) {
19
- if (cb) {
20
- cb();
21
- }
22
- return this;
23
- },
24
- [Symbol.toStringTag]: 'Promise',
25
- };
26
- }
27
- export function fakePromise(value) {
28
- if (isPromise(value)) {
29
- return value;
30
- }
31
- // Write a fake promise to avoid the promise constructor
32
- // being called with `new Promise` in the browser.
33
- return {
34
- then(resolve) {
35
- if (resolve) {
36
- const callbackResult = resolve(value);
37
- if (isPromise(callbackResult)) {
38
- return callbackResult;
39
- }
40
- return fakePromise(callbackResult);
41
- }
42
- return this;
43
- },
44
- catch() {
45
- return this;
46
- },
47
- finally(cb) {
48
- if (cb) {
49
- const callbackResult = cb();
50
- if (isPromise(callbackResult)) {
51
- return callbackResult.then(() => value);
52
- }
53
- return fakePromise(value);
54
- }
55
- return this;
56
- },
57
- [Symbol.toStringTag]: 'Promise',
58
- };
59
- }
@@ -1,23 +0,0 @@
1
- import { isPromise } from './jsutils.js';
2
- export function mapMaybePromise(value, mapper, errorMapper) {
3
- if (isPromise(value)) {
4
- if (errorMapper) {
5
- try {
6
- return value.then(mapper, errorMapper);
7
- }
8
- catch (e) {
9
- return errorMapper(e);
10
- }
11
- }
12
- return value.then(mapper);
13
- }
14
- if (errorMapper) {
15
- try {
16
- return mapper(value);
17
- }
18
- catch (e) {
19
- return errorMapper(e);
20
- }
21
- }
22
- return mapper(value);
23
- }
@@ -1,72 +0,0 @@
1
- import { fakePromise, fakeRejectPromise } from './fakePromise.js';
2
- import { mapMaybePromise } from './map-maybe-promise.js';
3
- /**
4
- * Given an AsyncIterable and a callback function, return an AsyncIterator
5
- * which produces values mapped via calling the callback function.
6
- */
7
- export function mapAsyncIterator(iterator, onNext, onError, onEnd) {
8
- if (Symbol.asyncIterator in iterator) {
9
- iterator = iterator[Symbol.asyncIterator]();
10
- }
11
- let $return;
12
- let abruptClose;
13
- let onEndWithValue;
14
- if (onEnd) {
15
- let onEndWithValueResult /** R in onEndWithValue */;
16
- onEndWithValue = value => {
17
- onEndWithValueResult ||= mapMaybePromise(onEnd(), () => value);
18
- return onEndWithValueResult;
19
- };
20
- }
21
- if (typeof iterator.return === 'function') {
22
- $return = iterator.return;
23
- abruptClose = (error) => {
24
- const rethrow = () => {
25
- throw error;
26
- };
27
- return $return.call(iterator).then(rethrow, rethrow);
28
- };
29
- }
30
- function mapResult(result) {
31
- if (result.done) {
32
- return onEndWithValue ? onEndWithValue(result) : result;
33
- }
34
- return mapMaybePromise(result.value, value => mapMaybePromise(onNext(value), iteratorResult, abruptClose));
35
- }
36
- let mapReject;
37
- if (onError) {
38
- let onErrorResult;
39
- // Capture rejectCallback to ensure it cannot be null.
40
- const reject = onError;
41
- mapReject = (error) => {
42
- onErrorResult ||= mapMaybePromise(error, error => mapMaybePromise(reject(error), iteratorResult, abruptClose));
43
- return onErrorResult;
44
- };
45
- }
46
- return {
47
- next() {
48
- return iterator.next().then(mapResult, mapReject);
49
- },
50
- return() {
51
- const res$ = $return
52
- ? $return.call(iterator).then(mapResult, mapReject)
53
- : fakePromise({ value: undefined, done: true });
54
- return onEndWithValue ? res$.then(onEndWithValue) : res$;
55
- },
56
- throw(error) {
57
- if (typeof iterator.throw === 'function') {
58
- return iterator.throw(error).then(mapResult, mapReject);
59
- }
60
- if (abruptClose) {
61
- return abruptClose(error);
62
- }
63
- return fakeRejectPromise(error);
64
- },
65
- [Symbol.asyncIterator]() {
66
- return this;
67
- },
68
- };
69
- }
70
- function iteratorResult(value) {
71
- return { value, done: false };
72
- }
@@ -1,6 +0,0 @@
1
- export interface PromiseWithResolvers<T> {
2
- promise: Promise<T>;
3
- resolve: (value: T | PromiseLike<T>) => void;
4
- reject: (reason: any) => void;
5
- }
6
- export declare function createDeferred<T>(): PromiseWithResolvers<T>;
@@ -1,6 +0,0 @@
1
- export interface PromiseWithResolvers<T> {
2
- promise: Promise<T>;
3
- resolve: (value: T | PromiseLike<T>) => void;
4
- reject: (reason: any) => void;
5
- }
6
- export declare function createDeferred<T>(): PromiseWithResolvers<T>;
@@ -1,4 +0,0 @@
1
- export declare function fakeRejectPromise(error: unknown): Promise<never>;
2
- export declare function fakePromise<const T>(value: T): Promise<T>;
3
- export declare function fakePromise<T>(value: T): Promise<T>;
4
- export declare function fakePromise(value: void): Promise<void>;
@@ -1,4 +0,0 @@
1
- export declare function fakeRejectPromise(error: unknown): Promise<never>;
2
- export declare function fakePromise<const T>(value: T): Promise<T>;
3
- export declare function fakePromise<T>(value: T): Promise<T>;
4
- export declare function fakePromise(value: void): Promise<void>;
@@ -1,2 +0,0 @@
1
- import { MaybePromise } from './executor.cjs';
2
- export declare function mapMaybePromise<T, R>(value: MaybePromise<T>, mapper: (v: T) => MaybePromise<R>, errorMapper?: (e: any) => MaybePromise<R>): MaybePromise<R>;
@@ -1,2 +0,0 @@
1
- import { MaybePromise } from './executor.js';
2
- export declare function mapMaybePromise<T, R>(value: MaybePromise<T>, mapper: (v: T) => MaybePromise<R>, errorMapper?: (e: any) => MaybePromise<R>): MaybePromise<R>;
@@ -1,6 +0,0 @@
1
- import type { MaybePromise } from './executor.cjs';
2
- /**
3
- * Given an AsyncIterable and a callback function, return an AsyncIterator
4
- * which produces values mapped via calling the callback function.
5
- */
6
- export declare function mapAsyncIterator<T, U>(iterator: AsyncIterable<T> | AsyncIterator<T>, onNext: (value: T) => MaybePromise<U>, onError?: any, onEnd?: () => MaybePromise<void>): AsyncIterableIterator<U>;
@@ -1,6 +0,0 @@
1
- import type { MaybePromise } from './executor.js';
2
- /**
3
- * Given an AsyncIterable and a callback function, return an AsyncIterator
4
- * which produces values mapped via calling the callback function.
5
- */
6
- export declare function mapAsyncIterator<T, U>(iterator: AsyncIterable<T> | AsyncIterator<T>, onNext: (value: T) => MaybePromise<U>, onError?: any, onEnd?: () => MaybePromise<void>): AsyncIterableIterator<U>;