@graphql-tools/utils 8.10.1 → 8.11.0-alpha-20220902151326-1cc04bb0
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/get-arguments-with-directives.js +33 -0
- package/cjs/get-fields-with-directives.js +1 -22
- package/cjs/index.js +1 -0
- package/esm/get-arguments-with-directives.js +29 -0
- package/esm/get-fields-with-directives.js +2 -23
- package/esm/index.js +1 -0
- package/package.json +1 -1
- package/typings/get-arguments-with-directives.d.cts +9 -0
- package/typings/get-arguments-with-directives.d.ts +9 -0
- package/typings/get-fields-with-directives.d.cts +1 -7
- package/typings/get-fields-with-directives.d.ts +1 -7
- package/typings/index.d.cts +1 -0
- package/typings/index.d.ts +1 -0
- package/typings/types.d.cts +7 -0
- package/typings/types.d.ts +7 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getArgumentsWithDirectives = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
function isTypeWithFields(t) {
|
|
6
|
+
return t.kind === graphql_1.Kind.OBJECT_TYPE_DEFINITION || t.kind === graphql_1.Kind.OBJECT_TYPE_EXTENSION;
|
|
7
|
+
}
|
|
8
|
+
function getArgumentsWithDirectives(documentNode) {
|
|
9
|
+
var _a;
|
|
10
|
+
const result = {};
|
|
11
|
+
const allTypes = documentNode.definitions.filter(isTypeWithFields);
|
|
12
|
+
for (const type of allTypes) {
|
|
13
|
+
if (type.fields == null) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
for (const field of type.fields) {
|
|
17
|
+
const argsWithDirectives = (_a = field.arguments) === null || _a === void 0 ? void 0 : _a.filter(arg => { var _a; return (_a = arg.directives) === null || _a === void 0 ? void 0 : _a.length; });
|
|
18
|
+
if (!(argsWithDirectives === null || argsWithDirectives === void 0 ? void 0 : argsWithDirectives.length)) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const typeFieldResult = (result[`${type.name.value}.${field.name.value}`] = {});
|
|
22
|
+
for (const arg of argsWithDirectives) {
|
|
23
|
+
const directives = arg.directives.map(d => ({
|
|
24
|
+
name: d.name.value,
|
|
25
|
+
args: (d.arguments || []).reduce((prev, dArg) => ({ ...prev, [dArg.name.value]: (0, graphql_1.valueFromASTUntyped)(dArg.value) }), {}),
|
|
26
|
+
}));
|
|
27
|
+
typeFieldResult[arg.name.value] = directives;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
exports.getArgumentsWithDirectives = getArgumentsWithDirectives;
|
|
@@ -2,27 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFieldsWithDirectives = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
|
-
function parseDirectiveValue(value) {
|
|
6
|
-
switch (value.kind) {
|
|
7
|
-
case graphql_1.Kind.INT:
|
|
8
|
-
return parseInt(value.value);
|
|
9
|
-
case graphql_1.Kind.FLOAT:
|
|
10
|
-
return parseFloat(value.value);
|
|
11
|
-
case graphql_1.Kind.BOOLEAN:
|
|
12
|
-
return Boolean(value.value);
|
|
13
|
-
case graphql_1.Kind.STRING:
|
|
14
|
-
case graphql_1.Kind.ENUM:
|
|
15
|
-
return value.value;
|
|
16
|
-
case graphql_1.Kind.LIST:
|
|
17
|
-
return value.values.map(v => parseDirectiveValue(v));
|
|
18
|
-
case graphql_1.Kind.OBJECT:
|
|
19
|
-
return value.fields.reduce((prev, v) => ({ ...prev, [v.name.value]: parseDirectiveValue(v.value) }), {});
|
|
20
|
-
case graphql_1.Kind.NULL:
|
|
21
|
-
return null;
|
|
22
|
-
default:
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
5
|
function getFieldsWithDirectives(documentNode, options = {}) {
|
|
27
6
|
const result = {};
|
|
28
7
|
let selected = ['ObjectTypeDefinition', 'ObjectTypeExtension'];
|
|
@@ -41,7 +20,7 @@ function getFieldsWithDirectives(documentNode, options = {}) {
|
|
|
41
20
|
const key = `${typeName}.${fieldName}`;
|
|
42
21
|
const directives = field.directives.map(d => ({
|
|
43
22
|
name: d.name.value,
|
|
44
|
-
args: (d.arguments || []).reduce((prev, arg) => ({ ...prev, [arg.name.value]:
|
|
23
|
+
args: (d.arguments || []).reduce((prev, arg) => ({ ...prev, [arg.name.value]: (0, graphql_1.valueFromASTUntyped)(arg.value) }), {}),
|
|
45
24
|
}));
|
|
46
25
|
result[key] = directives;
|
|
47
26
|
}
|
package/cjs/index.js
CHANGED
|
@@ -5,6 +5,7 @@ tslib_1.__exportStar(require("./loaders.js"), exports);
|
|
|
5
5
|
tslib_1.__exportStar(require("./helpers.js"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./get-directives.js"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./get-fields-with-directives.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./get-arguments-with-directives.js"), exports);
|
|
8
9
|
tslib_1.__exportStar(require("./get-implementing-types.js"), exports);
|
|
9
10
|
tslib_1.__exportStar(require("./print-schema-with-directives.js"), exports);
|
|
10
11
|
tslib_1.__exportStar(require("./get-fields-with-directives.js"), exports);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Kind, valueFromASTUntyped } from 'graphql';
|
|
2
|
+
function isTypeWithFields(t) {
|
|
3
|
+
return t.kind === Kind.OBJECT_TYPE_DEFINITION || t.kind === Kind.OBJECT_TYPE_EXTENSION;
|
|
4
|
+
}
|
|
5
|
+
export function getArgumentsWithDirectives(documentNode) {
|
|
6
|
+
var _a;
|
|
7
|
+
const result = {};
|
|
8
|
+
const allTypes = documentNode.definitions.filter(isTypeWithFields);
|
|
9
|
+
for (const type of allTypes) {
|
|
10
|
+
if (type.fields == null) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
for (const field of type.fields) {
|
|
14
|
+
const argsWithDirectives = (_a = field.arguments) === null || _a === void 0 ? void 0 : _a.filter(arg => { var _a; return (_a = arg.directives) === null || _a === void 0 ? void 0 : _a.length; });
|
|
15
|
+
if (!(argsWithDirectives === null || argsWithDirectives === void 0 ? void 0 : argsWithDirectives.length)) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const typeFieldResult = (result[`${type.name.value}.${field.name.value}`] = {});
|
|
19
|
+
for (const arg of argsWithDirectives) {
|
|
20
|
+
const directives = arg.directives.map(d => ({
|
|
21
|
+
name: d.name.value,
|
|
22
|
+
args: (d.arguments || []).reduce((prev, dArg) => ({ ...prev, [dArg.name.value]: valueFromASTUntyped(dArg.value) }), {}),
|
|
23
|
+
}));
|
|
24
|
+
typeFieldResult[arg.name.value] = directives;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
@@ -1,25 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
function parseDirectiveValue(value) {
|
|
3
|
-
switch (value.kind) {
|
|
4
|
-
case Kind.INT:
|
|
5
|
-
return parseInt(value.value);
|
|
6
|
-
case Kind.FLOAT:
|
|
7
|
-
return parseFloat(value.value);
|
|
8
|
-
case Kind.BOOLEAN:
|
|
9
|
-
return Boolean(value.value);
|
|
10
|
-
case Kind.STRING:
|
|
11
|
-
case Kind.ENUM:
|
|
12
|
-
return value.value;
|
|
13
|
-
case Kind.LIST:
|
|
14
|
-
return value.values.map(v => parseDirectiveValue(v));
|
|
15
|
-
case Kind.OBJECT:
|
|
16
|
-
return value.fields.reduce((prev, v) => ({ ...prev, [v.name.value]: parseDirectiveValue(v.value) }), {});
|
|
17
|
-
case Kind.NULL:
|
|
18
|
-
return null;
|
|
19
|
-
default:
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
1
|
+
import { valueFromASTUntyped, } from 'graphql';
|
|
23
2
|
export function getFieldsWithDirectives(documentNode, options = {}) {
|
|
24
3
|
const result = {};
|
|
25
4
|
let selected = ['ObjectTypeDefinition', 'ObjectTypeExtension'];
|
|
@@ -38,7 +17,7 @@ export function getFieldsWithDirectives(documentNode, options = {}) {
|
|
|
38
17
|
const key = `${typeName}.${fieldName}`;
|
|
39
18
|
const directives = field.directives.map(d => ({
|
|
40
19
|
name: d.name.value,
|
|
41
|
-
args: (d.arguments || []).reduce((prev, arg) => ({ ...prev, [arg.name.value]:
|
|
20
|
+
args: (d.arguments || []).reduce((prev, arg) => ({ ...prev, [arg.name.value]: valueFromASTUntyped(arg.value) }), {}),
|
|
42
21
|
}));
|
|
43
22
|
result[key] = directives;
|
|
44
23
|
}
|
package/esm/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from './loaders.js';
|
|
|
2
2
|
export * from './helpers.js';
|
|
3
3
|
export * from './get-directives.js';
|
|
4
4
|
export * from './get-fields-with-directives.js';
|
|
5
|
+
export * from './get-arguments-with-directives.js';
|
|
5
6
|
export * from './get-implementing-types.js';
|
|
6
7
|
export * from './print-schema-with-directives.js';
|
|
7
8
|
export * from './get-fields-with-directives.js';
|
package/package.json
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DirectiveUsage } from './types.cjs';
|
|
2
|
+
import { DocumentNode } from 'graphql';
|
|
3
|
+
export declare type ArgumentToDirectives = {
|
|
4
|
+
[argumentName: string]: DirectiveUsage[];
|
|
5
|
+
};
|
|
6
|
+
export declare type TypeAndFieldToArgumentDirectives = {
|
|
7
|
+
[typeAndField: string]: ArgumentToDirectives;
|
|
8
|
+
};
|
|
9
|
+
export declare function getArgumentsWithDirectives(documentNode: DocumentNode): TypeAndFieldToArgumentDirectives;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DirectiveUsage } from './types.js';
|
|
2
|
+
import { DocumentNode } from 'graphql';
|
|
3
|
+
export declare type ArgumentToDirectives = {
|
|
4
|
+
[argumentName: string]: DirectiveUsage[];
|
|
5
|
+
};
|
|
6
|
+
export declare type TypeAndFieldToArgumentDirectives = {
|
|
7
|
+
[typeAndField: string]: ArgumentToDirectives;
|
|
8
|
+
};
|
|
9
|
+
export declare function getArgumentsWithDirectives(documentNode: DocumentNode): TypeAndFieldToArgumentDirectives;
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { DocumentNode } from 'graphql';
|
|
2
|
-
|
|
3
|
-
[name: string]: any;
|
|
4
|
-
};
|
|
5
|
-
export declare type DirectiveUsage = {
|
|
6
|
-
name: string;
|
|
7
|
-
args: DirectiveArgs;
|
|
8
|
-
};
|
|
2
|
+
import { DirectiveUsage } from './types.cjs';
|
|
9
3
|
export declare type TypeAndFieldToDirectives = {
|
|
10
4
|
[typeAndField: string]: DirectiveUsage[];
|
|
11
5
|
};
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { DocumentNode } from 'graphql';
|
|
2
|
-
|
|
3
|
-
[name: string]: any;
|
|
4
|
-
};
|
|
5
|
-
export declare type DirectiveUsage = {
|
|
6
|
-
name: string;
|
|
7
|
-
args: DirectiveArgs;
|
|
8
|
-
};
|
|
2
|
+
import { DirectiveUsage } from './types.js';
|
|
9
3
|
export declare type TypeAndFieldToDirectives = {
|
|
10
4
|
[typeAndField: string]: DirectiveUsage[];
|
|
11
5
|
};
|
package/typings/index.d.cts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './loaders.cjs';
|
|
|
2
2
|
export * from './helpers.cjs';
|
|
3
3
|
export * from './get-directives.cjs';
|
|
4
4
|
export * from './get-fields-with-directives.cjs';
|
|
5
|
+
export * from './get-arguments-with-directives.cjs';
|
|
5
6
|
export * from './get-implementing-types.cjs';
|
|
6
7
|
export * from './print-schema-with-directives.cjs';
|
|
7
8
|
export * from './get-fields-with-directives.cjs';
|
package/typings/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './loaders.js';
|
|
|
2
2
|
export * from './helpers.js';
|
|
3
3
|
export * from './get-directives.js';
|
|
4
4
|
export * from './get-fields-with-directives.js';
|
|
5
|
+
export * from './get-arguments-with-directives.js';
|
|
5
6
|
export * from './get-implementing-types.js';
|
|
6
7
|
export * from './print-schema-with-directives.js';
|
|
7
8
|
export * from './get-fields-with-directives.js';
|
package/typings/types.d.cts
CHANGED
|
@@ -110,3 +110,10 @@ export declare type SchemaExtensions = {
|
|
|
110
110
|
extensions: ExtensionsObject;
|
|
111
111
|
} & PossibleTypeExtensions>;
|
|
112
112
|
};
|
|
113
|
+
export declare type DirectiveArgs = {
|
|
114
|
+
[name: string]: any;
|
|
115
|
+
};
|
|
116
|
+
export declare type DirectiveUsage = {
|
|
117
|
+
name: string;
|
|
118
|
+
args: DirectiveArgs;
|
|
119
|
+
};
|
package/typings/types.d.ts
CHANGED
|
@@ -110,3 +110,10 @@ export declare type SchemaExtensions = {
|
|
|
110
110
|
extensions: ExtensionsObject;
|
|
111
111
|
} & PossibleTypeExtensions>;
|
|
112
112
|
};
|
|
113
|
+
export declare type DirectiveArgs = {
|
|
114
|
+
[name: string]: any;
|
|
115
|
+
};
|
|
116
|
+
export declare type DirectiveUsage = {
|
|
117
|
+
name: string;
|
|
118
|
+
args: DirectiveArgs;
|
|
119
|
+
};
|