@graphql-inspector/action 3.4.13 → 3.4.14
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/commands/validate/src/index.js +32 -1
- package/cjs/core/src/validate/index.js +17 -0
- package/esm/commands/validate/src/index.js +32 -1
- package/esm/core/src/validate/index.js +17 -0
- package/package.json +3 -3
- package/typings/commands/validate/src/index.d.cts +7 -1
- package/typings/commands/validate/src/index.d.ts +7 -1
- package/typings/core/src/validate/complexity.d.cts +6 -0
- package/typings/core/src/validate/complexity.d.ts +6 -0
- package/typings/core/src/validate/index.d.cts +6 -0
- package/typings/core/src/validate/index.d.ts +6 -0
|
@@ -8,7 +8,7 @@ const graphql_1 = require("graphql");
|
|
|
8
8
|
const commands_1 = require("@graphql-inspector/commands");
|
|
9
9
|
const core_1 = require("@graphql-inspector/core");
|
|
10
10
|
const logger_1 = require("@graphql-inspector/logger");
|
|
11
|
-
function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, maxTokenCount, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }) {
|
|
11
|
+
function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, maxTokenCount, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, validateComplexityConfig, }) {
|
|
12
12
|
let invalidDocuments = (0, core_1.validate)(schema, documents.map(doc => new graphql_1.Source((0, graphql_1.print)(doc.document), doc.location)), {
|
|
13
13
|
strictFragments,
|
|
14
14
|
maxDepth,
|
|
@@ -17,6 +17,7 @@ function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCou
|
|
|
17
17
|
maxTokenCount,
|
|
18
18
|
apollo,
|
|
19
19
|
keepClientFields,
|
|
20
|
+
validateComplexityConfig,
|
|
20
21
|
});
|
|
21
22
|
if (!invalidDocuments.length) {
|
|
22
23
|
logger_1.Logger.success('All documents are valid');
|
|
@@ -163,6 +164,25 @@ exports.default = (0, commands_1.createCommand)(api => {
|
|
|
163
164
|
describe: 'Output JSON file',
|
|
164
165
|
type: 'string',
|
|
165
166
|
},
|
|
167
|
+
maxComplexityScore: {
|
|
168
|
+
describe: 'Fail on complexity score operations',
|
|
169
|
+
type: 'number',
|
|
170
|
+
},
|
|
171
|
+
complexityScalarCost: {
|
|
172
|
+
describe: 'Scalar cost config to use with maxComplexityScore',
|
|
173
|
+
type: 'number',
|
|
174
|
+
default: 1,
|
|
175
|
+
},
|
|
176
|
+
complexityObjectCost: {
|
|
177
|
+
describe: 'Object cost config to use with maxComplexityScore',
|
|
178
|
+
type: 'number',
|
|
179
|
+
default: 2,
|
|
180
|
+
},
|
|
181
|
+
complexityDepthCostFactor: {
|
|
182
|
+
describe: 'Depth cost factor config to use with maxComplexityScore',
|
|
183
|
+
type: 'number',
|
|
184
|
+
default: 1.5,
|
|
185
|
+
},
|
|
166
186
|
});
|
|
167
187
|
},
|
|
168
188
|
handler(args) {
|
|
@@ -185,6 +205,16 @@ exports.default = (0, commands_1.createCommand)(api => {
|
|
|
185
205
|
const relativePaths = args.relativePaths || false;
|
|
186
206
|
const onlyErrors = args.onlyErrors || false;
|
|
187
207
|
const ignore = args.ignore || [];
|
|
208
|
+
const validateComplexityConfig = (() => {
|
|
209
|
+
if (args.maxComplexityScore == null)
|
|
210
|
+
return;
|
|
211
|
+
return {
|
|
212
|
+
maxComplexityScore: args.maxComplexityScore,
|
|
213
|
+
complexityScalarCost: args.complexityScalarCost,
|
|
214
|
+
complexityObjectCost: args.complexityObjectCost,
|
|
215
|
+
complexityDepthCostFactor: args.complexityDepthCostFactor,
|
|
216
|
+
};
|
|
217
|
+
})();
|
|
188
218
|
const schema = yield loaders.loadSchema(args.schema, {
|
|
189
219
|
headers,
|
|
190
220
|
token,
|
|
@@ -209,6 +239,7 @@ exports.default = (0, commands_1.createCommand)(api => {
|
|
|
209
239
|
output,
|
|
210
240
|
relativePaths,
|
|
211
241
|
onlyErrors,
|
|
242
|
+
validateComplexityConfig,
|
|
212
243
|
});
|
|
213
244
|
});
|
|
214
245
|
},
|
|
@@ -7,6 +7,7 @@ const document_js_1 = require("../ast/document.js");
|
|
|
7
7
|
const apollo_js_1 = require("../utils/apollo.js");
|
|
8
8
|
const graphql_js_1 = require("../utils/graphql.js");
|
|
9
9
|
const alias_count_js_1 = require("./alias-count.js");
|
|
10
|
+
const complexity_1 = require("./complexity");
|
|
10
11
|
const directive_count_js_1 = require("./directive-count.js");
|
|
11
12
|
const query_depth_js_1 = require("./query-depth.js");
|
|
12
13
|
const token_count_js_1 = require("./token-count.js");
|
|
@@ -70,6 +71,22 @@ function validate(schema, sources, options) {
|
|
|
70
71
|
errors.push(depthError);
|
|
71
72
|
}
|
|
72
73
|
}
|
|
74
|
+
if (config.validateComplexityConfig) {
|
|
75
|
+
const complexityScoreError = (0, complexity_1.validateComplexity)({
|
|
76
|
+
source: doc.source,
|
|
77
|
+
doc: transformedDoc,
|
|
78
|
+
maxComplexityScore: config.validateComplexityConfig.maxComplexityScore,
|
|
79
|
+
config: {
|
|
80
|
+
scalarCost: config.validateComplexityConfig.complexityScalarCost,
|
|
81
|
+
objectCost: config.validateComplexityConfig.complexityObjectCost,
|
|
82
|
+
depthCostFactor: config.validateComplexityConfig.complexityDepthCostFactor,
|
|
83
|
+
},
|
|
84
|
+
fragmentGraph: graph,
|
|
85
|
+
});
|
|
86
|
+
if (complexityScoreError) {
|
|
87
|
+
errors.push(complexityScoreError);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
73
90
|
if (config.maxAliasCount) {
|
|
74
91
|
const aliasError = (0, alias_count_js_1.validateAliasCount)({
|
|
75
92
|
source: doc.source,
|
|
@@ -5,7 +5,7 @@ import { print, Source } from 'graphql';
|
|
|
5
5
|
import { createCommand, parseGlobalArgs, } from '@graphql-inspector/commands';
|
|
6
6
|
import { validate as validateDocuments } from '@graphql-inspector/core';
|
|
7
7
|
import { bolderize, chalk, Logger } from '@graphql-inspector/logger';
|
|
8
|
-
export function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, maxTokenCount, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }) {
|
|
8
|
+
export function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, maxTokenCount, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, validateComplexityConfig, }) {
|
|
9
9
|
let invalidDocuments = validateDocuments(schema, documents.map(doc => new Source(print(doc.document), doc.location)), {
|
|
10
10
|
strictFragments,
|
|
11
11
|
maxDepth,
|
|
@@ -14,6 +14,7 @@ export function handler({ schema, documents, strictFragments, maxDepth, maxDirec
|
|
|
14
14
|
maxTokenCount,
|
|
15
15
|
apollo,
|
|
16
16
|
keepClientFields,
|
|
17
|
+
validateComplexityConfig,
|
|
17
18
|
});
|
|
18
19
|
if (!invalidDocuments.length) {
|
|
19
20
|
Logger.success('All documents are valid');
|
|
@@ -159,6 +160,25 @@ export default createCommand(api => {
|
|
|
159
160
|
describe: 'Output JSON file',
|
|
160
161
|
type: 'string',
|
|
161
162
|
},
|
|
163
|
+
maxComplexityScore: {
|
|
164
|
+
describe: 'Fail on complexity score operations',
|
|
165
|
+
type: 'number',
|
|
166
|
+
},
|
|
167
|
+
complexityScalarCost: {
|
|
168
|
+
describe: 'Scalar cost config to use with maxComplexityScore',
|
|
169
|
+
type: 'number',
|
|
170
|
+
default: 1,
|
|
171
|
+
},
|
|
172
|
+
complexityObjectCost: {
|
|
173
|
+
describe: 'Object cost config to use with maxComplexityScore',
|
|
174
|
+
type: 'number',
|
|
175
|
+
default: 2,
|
|
176
|
+
},
|
|
177
|
+
complexityDepthCostFactor: {
|
|
178
|
+
describe: 'Depth cost factor config to use with maxComplexityScore',
|
|
179
|
+
type: 'number',
|
|
180
|
+
default: 1.5,
|
|
181
|
+
},
|
|
162
182
|
});
|
|
163
183
|
},
|
|
164
184
|
handler(args) {
|
|
@@ -181,6 +201,16 @@ export default createCommand(api => {
|
|
|
181
201
|
const relativePaths = args.relativePaths || false;
|
|
182
202
|
const onlyErrors = args.onlyErrors || false;
|
|
183
203
|
const ignore = args.ignore || [];
|
|
204
|
+
const validateComplexityConfig = (() => {
|
|
205
|
+
if (args.maxComplexityScore == null)
|
|
206
|
+
return;
|
|
207
|
+
return {
|
|
208
|
+
maxComplexityScore: args.maxComplexityScore,
|
|
209
|
+
complexityScalarCost: args.complexityScalarCost,
|
|
210
|
+
complexityObjectCost: args.complexityObjectCost,
|
|
211
|
+
complexityDepthCostFactor: args.complexityDepthCostFactor,
|
|
212
|
+
};
|
|
213
|
+
})();
|
|
184
214
|
const schema = yield loaders.loadSchema(args.schema, {
|
|
185
215
|
headers,
|
|
186
216
|
token,
|
|
@@ -205,6 +235,7 @@ export default createCommand(api => {
|
|
|
205
235
|
output,
|
|
206
236
|
relativePaths,
|
|
207
237
|
onlyErrors,
|
|
238
|
+
validateComplexityConfig,
|
|
208
239
|
});
|
|
209
240
|
});
|
|
210
241
|
},
|
|
@@ -4,6 +4,7 @@ import { readDocument } from '../ast/document.js';
|
|
|
4
4
|
import { transformDocumentWithApollo, transformSchemaWithApollo } from '../utils/apollo.js';
|
|
5
5
|
import { findDeprecatedUsages } from '../utils/graphql.js';
|
|
6
6
|
import { validateAliasCount } from './alias-count.js';
|
|
7
|
+
import { validateComplexity } from './complexity';
|
|
7
8
|
import { validateDirectiveCount } from './directive-count.js';
|
|
8
9
|
import { validateQueryDepth } from './query-depth.js';
|
|
9
10
|
import { validateTokenCount } from './token-count.js';
|
|
@@ -67,6 +68,22 @@ export function validate(schema, sources, options) {
|
|
|
67
68
|
errors.push(depthError);
|
|
68
69
|
}
|
|
69
70
|
}
|
|
71
|
+
if (config.validateComplexityConfig) {
|
|
72
|
+
const complexityScoreError = validateComplexity({
|
|
73
|
+
source: doc.source,
|
|
74
|
+
doc: transformedDoc,
|
|
75
|
+
maxComplexityScore: config.validateComplexityConfig.maxComplexityScore,
|
|
76
|
+
config: {
|
|
77
|
+
scalarCost: config.validateComplexityConfig.complexityScalarCost,
|
|
78
|
+
objectCost: config.validateComplexityConfig.complexityObjectCost,
|
|
79
|
+
depthCostFactor: config.validateComplexityConfig.complexityDepthCostFactor,
|
|
80
|
+
},
|
|
81
|
+
fragmentGraph: graph,
|
|
82
|
+
});
|
|
83
|
+
if (complexityScoreError) {
|
|
84
|
+
errors.push(complexityScoreError);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
70
87
|
if (config.maxAliasCount) {
|
|
71
88
|
const aliasError = validateAliasCount({
|
|
72
89
|
source: doc.source,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-inspector/action",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.14",
|
|
4
4
|
"description": "GraphQL Inspector functionality for GitHub Actions",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"dependencies": {
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"probot": "12.3.0",
|
|
11
11
|
"tslib": "2.5.0",
|
|
12
12
|
"@graphql-inspector/commands": "3.4.6",
|
|
13
|
-
"@graphql-inspector/core": "4.
|
|
14
|
-
"@graphql-inspector/github": "3.4.
|
|
13
|
+
"@graphql-inspector/core": "4.2.0",
|
|
14
|
+
"@graphql-inspector/github": "3.4.12"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { ValidateOperationComplexityConfig } from 'packages/core/src/validate/complexity';
|
|
2
3
|
import { CommandFactory, GlobalArgs } from '@graphql-inspector/commands';
|
|
3
4
|
import { Source as DocumentSource } from '@graphql-tools/utils';
|
|
4
5
|
export { CommandFactory };
|
|
5
|
-
export declare function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, maxTokenCount, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }: {
|
|
6
|
+
export declare function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, maxTokenCount, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, validateComplexityConfig, }: {
|
|
6
7
|
schema: GraphQLSchema;
|
|
7
8
|
documents: DocumentSource[];
|
|
8
9
|
failOnDeprecated: boolean;
|
|
@@ -18,6 +19,7 @@ export declare function handler({ schema, documents, strictFragments, maxDepth,
|
|
|
18
19
|
relativePaths?: boolean;
|
|
19
20
|
output?: string;
|
|
20
21
|
silent?: boolean;
|
|
22
|
+
validateComplexityConfig?: ValidateOperationComplexityConfig;
|
|
21
23
|
}): void;
|
|
22
24
|
declare const _default: CommandFactory<{}, {
|
|
23
25
|
schema: string;
|
|
@@ -36,5 +38,9 @@ declare const _default: CommandFactory<{}, {
|
|
|
36
38
|
output?: string | undefined;
|
|
37
39
|
silent?: boolean | undefined;
|
|
38
40
|
ignore?: string[] | undefined;
|
|
41
|
+
maxComplexityScore?: number | undefined;
|
|
42
|
+
complexityScalarCost: number;
|
|
43
|
+
complexityObjectCost: number;
|
|
44
|
+
complexityDepthCostFactor: number;
|
|
39
45
|
} & GlobalArgs>;
|
|
40
46
|
export default _default;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { ValidateOperationComplexityConfig } from 'packages/core/src/validate/complexity';
|
|
2
3
|
import { CommandFactory, GlobalArgs } from '@graphql-inspector/commands';
|
|
3
4
|
import { Source as DocumentSource } from '@graphql-tools/utils';
|
|
4
5
|
export { CommandFactory };
|
|
5
|
-
export declare function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, maxTokenCount, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }: {
|
|
6
|
+
export declare function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, maxTokenCount, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, validateComplexityConfig, }: {
|
|
6
7
|
schema: GraphQLSchema;
|
|
7
8
|
documents: DocumentSource[];
|
|
8
9
|
failOnDeprecated: boolean;
|
|
@@ -18,6 +19,7 @@ export declare function handler({ schema, documents, strictFragments, maxDepth,
|
|
|
18
19
|
relativePaths?: boolean;
|
|
19
20
|
output?: string;
|
|
20
21
|
silent?: boolean;
|
|
22
|
+
validateComplexityConfig?: ValidateOperationComplexityConfig;
|
|
21
23
|
}): void;
|
|
22
24
|
declare const _default: CommandFactory<{}, {
|
|
23
25
|
schema: string;
|
|
@@ -36,5 +38,9 @@ declare const _default: CommandFactory<{}, {
|
|
|
36
38
|
output?: string | undefined;
|
|
37
39
|
silent?: boolean | undefined;
|
|
38
40
|
ignore?: string[] | undefined;
|
|
41
|
+
maxComplexityScore?: number | undefined;
|
|
42
|
+
complexityScalarCost: number;
|
|
43
|
+
complexityObjectCost: number;
|
|
44
|
+
complexityDepthCostFactor: number;
|
|
39
45
|
} & GlobalArgs>;
|
|
40
46
|
export default _default;
|
|
@@ -6,6 +6,12 @@ export type CalculateOperationComplexityConfig = {
|
|
|
6
6
|
objectCost: number;
|
|
7
7
|
depthCostFactor: number;
|
|
8
8
|
};
|
|
9
|
+
export type ValidateOperationComplexityConfig = {
|
|
10
|
+
maxComplexityScore: number;
|
|
11
|
+
complexityScalarCost: number;
|
|
12
|
+
complexityObjectCost: number;
|
|
13
|
+
complexityDepthCostFactor: number;
|
|
14
|
+
};
|
|
9
15
|
export declare function validateComplexity({ source, doc, maxComplexityScore, config, fragmentGraph, }: {
|
|
10
16
|
source: Source;
|
|
11
17
|
doc: DocumentNode;
|
|
@@ -6,6 +6,12 @@ export type CalculateOperationComplexityConfig = {
|
|
|
6
6
|
objectCost: number;
|
|
7
7
|
depthCostFactor: number;
|
|
8
8
|
};
|
|
9
|
+
export type ValidateOperationComplexityConfig = {
|
|
10
|
+
maxComplexityScore: number;
|
|
11
|
+
complexityScalarCost: number;
|
|
12
|
+
complexityObjectCost: number;
|
|
13
|
+
complexityDepthCostFactor: number;
|
|
14
|
+
};
|
|
9
15
|
export declare function validateComplexity({ source, doc, maxComplexityScore, config, fragmentGraph, }: {
|
|
10
16
|
source: Source;
|
|
11
17
|
doc: DocumentNode;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GraphQLError, GraphQLSchema, Source } from 'graphql';
|
|
2
|
+
import { ValidateOperationComplexityConfig } from './complexity';
|
|
2
3
|
export interface InvalidDocument {
|
|
3
4
|
source: Source;
|
|
4
5
|
errors: GraphQLError[];
|
|
@@ -45,5 +46,10 @@ export interface ValidateOptions {
|
|
|
45
46
|
* @default Infinity
|
|
46
47
|
*/
|
|
47
48
|
maxTokenCount?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Fails when complexity score exceeds maximum complexity score (including the referenced fragments).
|
|
51
|
+
* @default Infinity
|
|
52
|
+
*/
|
|
53
|
+
validateComplexityConfig?: ValidateOperationComplexityConfig;
|
|
48
54
|
}
|
|
49
55
|
export declare function validate(schema: GraphQLSchema, sources: Source[], options?: ValidateOptions): InvalidDocument[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GraphQLError, GraphQLSchema, Source } from 'graphql';
|
|
2
|
+
import { ValidateOperationComplexityConfig } from './complexity';
|
|
2
3
|
export interface InvalidDocument {
|
|
3
4
|
source: Source;
|
|
4
5
|
errors: GraphQLError[];
|
|
@@ -45,5 +46,10 @@ export interface ValidateOptions {
|
|
|
45
46
|
* @default Infinity
|
|
46
47
|
*/
|
|
47
48
|
maxTokenCount?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Fails when complexity score exceeds maximum complexity score (including the referenced fragments).
|
|
51
|
+
* @default Infinity
|
|
52
|
+
*/
|
|
53
|
+
validateComplexityConfig?: ValidateOperationComplexityConfig;
|
|
48
54
|
}
|
|
49
55
|
export declare function validate(schema: GraphQLSchema, sources: Source[], options?: ValidateOptions): InvalidDocument[];
|