@graphql-tools/utils 13.0.1 → 13.0.2
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/index.js +1 -0
- package/cjs/variableValues.js +51 -0
- package/esm/index.js +1 -0
- package/esm/variableValues.js +47 -0
- package/package.json +1 -1
- package/typings/index.d.cts +1 -0
- package/typings/index.d.ts +1 -0
- package/typings/variableValues.d.cts +26 -0
- package/typings/variableValues.d.ts +26 -0
package/cjs/index.js
CHANGED
|
@@ -56,4 +56,5 @@ tslib_1.__exportStar(require("./directives.js"), exports);
|
|
|
56
56
|
tslib_1.__exportStar(require("./mergeIncrementalResult.js"), exports);
|
|
57
57
|
tslib_1.__exportStar(require("./getDirectiveExtensions.js"), exports);
|
|
58
58
|
tslib_1.__exportStar(require("./getDirectiveValues.js"), exports);
|
|
59
|
+
tslib_1.__exportStar(require("./variableValues.js"), exports);
|
|
59
60
|
tslib_1.__exportStar(require("./memoize.js"), exports);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asGetArgumentValuesVariables = asGetArgumentValuesVariables;
|
|
4
|
+
exports.coerceGetVariableValuesResult = coerceGetVariableValuesResult;
|
|
5
|
+
const graphql_1 = require("graphql");
|
|
6
|
+
function emptySources() {
|
|
7
|
+
return Object.create(null);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* GraphQL 17 `getArgumentValues` expects `{ coerced, sources }`; GraphQL 16 accepts a flat map.
|
|
11
|
+
* Pass execution `variableValues` (often a flat record) through this helper before calling
|
|
12
|
+
* `getArgumentValues`.
|
|
13
|
+
*/
|
|
14
|
+
function asGetArgumentValuesVariables(variableValues) {
|
|
15
|
+
if (variableValues == null) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
if (graphql_1.versionInfo.major >= 17 && !('coerced' in variableValues)) {
|
|
19
|
+
return {
|
|
20
|
+
coerced: variableValues,
|
|
21
|
+
sources: emptySources(),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return variableValues;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Normalize `getVariableValues` success/error shapes across GraphQL 16 (`{ coerced }`) and
|
|
28
|
+
* GraphQL 17 (`{ variableValues: { coerced, sources } }`) for helpers like `shouldIncludeNode`.
|
|
29
|
+
*/
|
|
30
|
+
function coerceGetVariableValuesResult(result) {
|
|
31
|
+
if (result.errors != null && result.errors.length > 0) {
|
|
32
|
+
return { errors: result.errors };
|
|
33
|
+
}
|
|
34
|
+
if (result.variableValues != null) {
|
|
35
|
+
return { variableValues: result.variableValues };
|
|
36
|
+
}
|
|
37
|
+
if (result.coerced != null) {
|
|
38
|
+
return {
|
|
39
|
+
variableValues: {
|
|
40
|
+
coerced: result.coerced,
|
|
41
|
+
sources: emptySources(),
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
variableValues: {
|
|
47
|
+
coerced: Object.create(null),
|
|
48
|
+
sources: emptySources(),
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
package/esm/index.js
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { versionInfo } from 'graphql';
|
|
2
|
+
function emptySources() {
|
|
3
|
+
return Object.create(null);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* GraphQL 17 `getArgumentValues` expects `{ coerced, sources }`; GraphQL 16 accepts a flat map.
|
|
7
|
+
* Pass execution `variableValues` (often a flat record) through this helper before calling
|
|
8
|
+
* `getArgumentValues`.
|
|
9
|
+
*/
|
|
10
|
+
export function asGetArgumentValuesVariables(variableValues) {
|
|
11
|
+
if (variableValues == null) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
if (versionInfo.major >= 17 && !('coerced' in variableValues)) {
|
|
15
|
+
return {
|
|
16
|
+
coerced: variableValues,
|
|
17
|
+
sources: emptySources(),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return variableValues;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Normalize `getVariableValues` success/error shapes across GraphQL 16 (`{ coerced }`) and
|
|
24
|
+
* GraphQL 17 (`{ variableValues: { coerced, sources } }`) for helpers like `shouldIncludeNode`.
|
|
25
|
+
*/
|
|
26
|
+
export function coerceGetVariableValuesResult(result) {
|
|
27
|
+
if (result.errors != null && result.errors.length > 0) {
|
|
28
|
+
return { errors: result.errors };
|
|
29
|
+
}
|
|
30
|
+
if (result.variableValues != null) {
|
|
31
|
+
return { variableValues: result.variableValues };
|
|
32
|
+
}
|
|
33
|
+
if (result.coerced != null) {
|
|
34
|
+
return {
|
|
35
|
+
variableValues: {
|
|
36
|
+
coerced: result.coerced,
|
|
37
|
+
sources: emptySources(),
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
variableValues: {
|
|
43
|
+
coerced: Object.create(null),
|
|
44
|
+
sources: emptySources(),
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
package/package.json
CHANGED
package/typings/index.d.cts
CHANGED
package/typings/index.d.ts
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { GraphQLError } from 'graphql';
|
|
2
|
+
import { getArgumentValues } from 'graphql';
|
|
3
|
+
import type { VariableValues } from './types.cjs';
|
|
4
|
+
type FlatVariableMap = {
|
|
5
|
+
readonly [variable: string]: unknown;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* GraphQL 17 `getArgumentValues` expects `{ coerced, sources }`; GraphQL 16 accepts a flat map.
|
|
9
|
+
* Pass execution `variableValues` (often a flat record) through this helper before calling
|
|
10
|
+
* `getArgumentValues`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function asGetArgumentValuesVariables(variableValues: FlatVariableMap | null | undefined): Parameters<typeof getArgumentValues>[2];
|
|
13
|
+
/**
|
|
14
|
+
* Normalize `getVariableValues` success/error shapes across GraphQL 16 (`{ coerced }`) and
|
|
15
|
+
* GraphQL 17 (`{ variableValues: { coerced, sources } }`) for helpers like `shouldIncludeNode`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function coerceGetVariableValuesResult(result: {
|
|
18
|
+
errors?: ReadonlyArray<GraphQLError>;
|
|
19
|
+
variableValues?: VariableValues;
|
|
20
|
+
coerced?: FlatVariableMap;
|
|
21
|
+
}): {
|
|
22
|
+
readonly errors: ReadonlyArray<GraphQLError>;
|
|
23
|
+
} | {
|
|
24
|
+
readonly variableValues: VariableValues;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { GraphQLError } from 'graphql';
|
|
2
|
+
import { getArgumentValues } from 'graphql';
|
|
3
|
+
import type { VariableValues } from './types.js';
|
|
4
|
+
type FlatVariableMap = {
|
|
5
|
+
readonly [variable: string]: unknown;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* GraphQL 17 `getArgumentValues` expects `{ coerced, sources }`; GraphQL 16 accepts a flat map.
|
|
9
|
+
* Pass execution `variableValues` (often a flat record) through this helper before calling
|
|
10
|
+
* `getArgumentValues`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function asGetArgumentValuesVariables(variableValues: FlatVariableMap | null | undefined): Parameters<typeof getArgumentValues>[2];
|
|
13
|
+
/**
|
|
14
|
+
* Normalize `getVariableValues` success/error shapes across GraphQL 16 (`{ coerced }`) and
|
|
15
|
+
* GraphQL 17 (`{ variableValues: { coerced, sources } }`) for helpers like `shouldIncludeNode`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function coerceGetVariableValuesResult(result: {
|
|
18
|
+
errors?: ReadonlyArray<GraphQLError>;
|
|
19
|
+
variableValues?: VariableValues;
|
|
20
|
+
coerced?: FlatVariableMap;
|
|
21
|
+
}): {
|
|
22
|
+
readonly errors: ReadonlyArray<GraphQLError>;
|
|
23
|
+
} | {
|
|
24
|
+
readonly variableValues: VariableValues;
|
|
25
|
+
};
|
|
26
|
+
export {};
|