@graphql-inspector/cli 6.0.8 → 7.0.0

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 (41) hide show
  1. package/cjs/action/src/action.js +0 -3
  2. package/cjs/action/src/run.js +5 -1
  3. package/cjs/action/src/utils.js +6 -1
  4. package/cjs/core/src/diff/argument.js +5 -12
  5. package/cjs/core/src/diff/changes/argument.js +6 -4
  6. package/cjs/core/src/diff/changes/directive.js +9 -5
  7. package/cjs/core/src/diff/changes/field.js +3 -2
  8. package/cjs/core/src/diff/changes/input.js +8 -7
  9. package/cjs/core/src/diff/directive.js +2 -1
  10. package/cjs/core/src/diff/input.js +5 -11
  11. package/cjs/core/src/utils/graphql.js +43 -3
  12. package/cjs/core/src/validate/alias-count.js +5 -1
  13. package/cjs/core/src/validate/complexity.js +5 -1
  14. package/cjs/core/src/validate/directive-count.js +5 -1
  15. package/cjs/core/src/validate/query-depth.js +5 -1
  16. package/cjs/core/src/validate/token-count.js +5 -1
  17. package/esm/action/src/action.js +0 -3
  18. package/esm/action/src/run.js +5 -1
  19. package/esm/action/src/utils.js +6 -1
  20. package/esm/core/src/diff/argument.js +6 -13
  21. package/esm/core/src/diff/changes/argument.js +7 -5
  22. package/esm/core/src/diff/changes/directive.js +10 -6
  23. package/esm/core/src/diff/changes/field.js +4 -3
  24. package/esm/core/src/diff/changes/input.js +9 -8
  25. package/esm/core/src/diff/directive.js +2 -1
  26. package/esm/core/src/diff/input.js +6 -12
  27. package/esm/core/src/utils/graphql.js +41 -4
  28. package/esm/core/src/validate/alias-count.js +5 -1
  29. package/esm/core/src/validate/complexity.js +5 -1
  30. package/esm/core/src/validate/directive-count.js +5 -1
  31. package/esm/core/src/validate/query-depth.js +5 -1
  32. package/esm/core/src/validate/token-count.js +5 -1
  33. package/package.json +22 -22
  34. package/typings/core/src/diff/changes/change.d.cts +1 -1
  35. package/typings/core/src/diff/changes/change.d.ts +1 -1
  36. package/typings/core/src/diff/changes/directive.d.cts +3 -3
  37. package/typings/core/src/diff/changes/directive.d.ts +3 -3
  38. package/typings/core/src/diff/changes/type.d.cts +3 -3
  39. package/typings/core/src/diff/changes/type.d.ts +3 -3
  40. package/typings/core/src/utils/graphql.d.cts +15 -2
  41. package/typings/core/src/utils/graphql.d.ts +15 -2
@@ -3,9 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const core = tslib_1.__importStar(require("@actions/core"));
5
5
  const run_js_1 = require("./run.js");
6
- global.navigator = {
7
- userAgent: 'node.js',
8
- };
9
6
  (0, run_js_1.run)().catch(e => {
10
7
  core.setFailed(e.message || e);
11
8
  });
@@ -76,7 +76,11 @@ async function run() {
76
76
  }
77
77
  let config;
78
78
  if (onUsage) {
79
- const checkUsage = require(onUsage);
79
+ // real runtime require so ncc doesn't try to resolve it from the bundle
80
+ const checkUsage = process
81
+ // @ts-expect-error getBuiltinModule exists starting node v20.16.0
82
+ .getBuiltinModule('module')
83
+ .createRequire(import.meta.url)(onUsage);
80
84
  if (checkUsage) {
81
85
  config = {
82
86
  checkUsage,
@@ -48,7 +48,12 @@ function getInputAsArray(name, options) {
48
48
  function resolveRule(name) {
49
49
  const filepath = (0, commands_1.ensureAbsolute)(name);
50
50
  if ((0, fs_1.existsSync)(filepath)) {
51
- return require(filepath);
51
+ // ncc rewrites bare require to its bundler require, which can't load files
52
+ // outside the bundle. createRequire gives us a real runtime require.
53
+ return (process
54
+ // @ts-expect-error getBuiltinModule exists starting node v20.16.0
55
+ .getBuiltinModule('module')
56
+ .createRequire(import.meta.url)(filepath));
52
57
  }
53
58
  return core_1.DiffRule[name];
54
59
  }
@@ -3,28 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.changesInArgument = changesInArgument;
4
4
  const graphql_1 = require("graphql");
5
5
  const compare_js_1 = require("../utils/compare.js");
6
+ const graphql_js_1 = require("../utils/graphql.js");
6
7
  const argument_js_1 = require("./changes/argument.js");
7
8
  const directive_usage_js_1 = require("./changes/directive-usage.js");
8
9
  function changesInArgument(type, field, oldArg, newArg, addChange) {
9
10
  if ((0, compare_js_1.isNotEqual)(oldArg?.description, newArg.description)) {
10
11
  addChange((0, argument_js_1.fieldArgumentDescriptionChanged)(type, field, oldArg, newArg));
11
12
  }
12
- if ((0, compare_js_1.isNotEqual)(oldArg?.defaultValue, newArg.defaultValue)) {
13
- if (Array.isArray(oldArg?.defaultValue) && Array.isArray(newArg.defaultValue)) {
14
- const diff = (0, compare_js_1.diffArrays)(oldArg.defaultValue, newArg.defaultValue);
15
- if (diff.length > 0) {
16
- addChange((0, argument_js_1.fieldArgumentDefaultChanged)(type, field, oldArg, newArg));
17
- }
18
- }
19
- else if (JSON.stringify(oldArg?.defaultValue) !== JSON.stringify(newArg.defaultValue)) {
20
- addChange((0, argument_js_1.fieldArgumentDefaultChanged)(type, field, oldArg, newArg));
21
- }
13
+ if (!(0, graphql_js_1.defaultValuesAreEqual)(oldArg, newArg)) {
14
+ addChange((0, argument_js_1.fieldArgumentDefaultChanged)(type, field, oldArg, newArg));
22
15
  }
23
16
  if ((0, compare_js_1.isNotEqual)(oldArg?.type.toString(), newArg.type.toString())) {
24
17
  addChange((0, argument_js_1.fieldArgumentTypeChanged)(type, field, oldArg, newArg));
25
18
  }
26
- if (newArg.astNode?.directives) {
27
- (0, compare_js_1.compareDirectiveLists)(oldArg?.astNode?.directives || [], newArg.astNode.directives || [], {
19
+ if (oldArg?.astNode?.directives || newArg.astNode?.directives) {
20
+ (0, compare_js_1.compareDirectiveLists)(oldArg?.astNode?.directives || [], newArg.astNode?.directives || [], {
28
21
  onAdded(directive) {
29
22
  addChange((0, directive_usage_js_1.directiveUsageAdded)(graphql_1.Kind.ARGUMENT, directive, {
30
23
  argument: newArg,
@@ -65,11 +65,13 @@ function fieldArgumentDefaultChanged(type, field, oldArg, newArg) {
65
65
  fieldName: field.name,
66
66
  argumentName: newArg.name,
67
67
  };
68
- if (oldArg?.defaultValue !== undefined) {
69
- meta.oldDefaultValue = (0, string_js_1.safeString)(oldArg.defaultValue);
68
+ const oldDefaultValue = oldArg === null ? undefined : (0, graphql_js_1.getDefaultValue)(oldArg);
69
+ const newDefaultValue = (0, graphql_js_1.getDefaultValue)(newArg);
70
+ if (oldDefaultValue !== undefined) {
71
+ meta.oldDefaultValue = (0, string_js_1.safeString)(oldDefaultValue);
70
72
  }
71
- if (newArg.defaultValue !== undefined) {
72
- meta.newDefaultValue = (0, string_js_1.safeString)(newArg.defaultValue);
73
+ if (newDefaultValue !== undefined) {
74
+ meta.newDefaultValue = (0, string_js_1.safeString)(newDefaultValue);
73
75
  }
74
76
  return fieldArgumentDefaultChangedFromMeta({
75
77
  type: change_js_1.ChangeType.FieldArgumentDefaultChanged,
@@ -231,7 +231,9 @@ function directiveArgumentAdded(directive, arg, addedToNewDirective) {
231
231
  directiveName: directive.name,
232
232
  addedDirectiveArgumentName: arg.name,
233
233
  addedDirectiveArgumentType: arg.type.toString(),
234
- addedDirectiveDefaultValue: arg.defaultValue === undefined ? undefined : (0, string_js_1.safeString)(arg.defaultValue),
234
+ addedDirectiveDefaultValue: (0, graphql_js_1.hasDefaultValue)(arg)
235
+ ? (0, string_js_1.safeString)((0, graphql_js_1.getDefaultValue)(arg))
236
+ : undefined,
235
237
  addedDirectiveArgumentTypeIsNonNull: (0, graphql_1.isNonNullType)(arg.type),
236
238
  addedDirectiveArgumentDescription: arg.description ?? undefined,
237
239
  addedToNewDirective,
@@ -319,11 +321,13 @@ function directiveArgumentDefaultValueChanged(directive, oldArg, newArg) {
319
321
  directiveName: directive.name,
320
322
  directiveArgumentName: newArg.name,
321
323
  };
322
- if (oldArg?.defaultValue !== undefined) {
323
- meta.oldDirectiveArgumentDefaultValue = (0, string_js_1.safeString)(oldArg.defaultValue);
324
+ const oldDefaultValue = oldArg === null ? undefined : (0, graphql_js_1.getDefaultValue)(oldArg);
325
+ const newDefaultValue = (0, graphql_js_1.getDefaultValue)(newArg);
326
+ if (oldDefaultValue !== undefined) {
327
+ meta.oldDirectiveArgumentDefaultValue = (0, string_js_1.safeString)(oldDefaultValue);
324
328
  }
325
- if (newArg.defaultValue !== undefined) {
326
- meta.newDirectiveArgumentDefaultValue = (0, string_js_1.safeString)(newArg.defaultValue);
329
+ if (newDefaultValue !== undefined) {
330
+ meta.newDirectiveArgumentDefaultValue = (0, string_js_1.safeString)(newDefaultValue);
327
331
  }
328
332
  return directiveArgumentDefaultValueChangedFromMeta({
329
333
  type: change_js_1.ChangeType.DirectiveArgumentDefaultValueChanged,
@@ -327,7 +327,8 @@ function fieldArgumentAddedFromMeta(args) {
327
327
  };
328
328
  }
329
329
  function fieldArgumentAdded(type, field, arg, addedToNewField) {
330
- const isBreaking = (0, graphql_1.isNonNullType)(arg.type) && typeof arg.defaultValue === 'undefined';
330
+ const hasDefault = (0, graphql_js_1.hasDefaultValue)(arg);
331
+ const isBreaking = (0, graphql_1.isNonNullType)(arg.type) && !hasDefault;
331
332
  return fieldArgumentAddedFromMeta({
332
333
  type: change_js_1.ChangeType.FieldArgumentAdded,
333
334
  meta: {
@@ -335,7 +336,7 @@ function fieldArgumentAdded(type, field, arg, addedToNewField) {
335
336
  fieldName: field.name,
336
337
  addedArgumentName: arg.name,
337
338
  addedArgumentType: arg.type.toString(),
338
- hasDefaultValue: arg.defaultValue != null,
339
+ hasDefaultValue: hasDefault,
339
340
  addedToNewField,
340
341
  isAddedFieldArgumentBreaking: isBreaking,
341
342
  },
@@ -84,6 +84,7 @@ function inputFieldAddedFromMeta(args) {
84
84
  };
85
85
  }
86
86
  function inputFieldAdded(input, field, addedToNewType) {
87
+ const defaultValue = (0, graphql_js_1.getDefaultValue)(field);
87
88
  return inputFieldAddedFromMeta({
88
89
  type: change_js_1.ChangeType.InputFieldAdded,
89
90
  meta: {
@@ -91,9 +92,7 @@ function inputFieldAdded(input, field, addedToNewType) {
91
92
  addedInputFieldName: field.name,
92
93
  isAddedInputFieldTypeNullable: !(0, graphql_1.isNonNullType)(field.type),
93
94
  addedInputFieldType: field.type.toString(),
94
- ...(field.defaultValue === undefined
95
- ? {}
96
- : { addedFieldDefault: (0, string_js_1.safeString)(field.defaultValue) }),
95
+ ...((0, graphql_js_1.hasDefaultValue)(field) ? { addedFieldDefault: (0, string_js_1.safeString)(defaultValue) } : {}),
97
96
  addedToNewType,
98
97
  },
99
98
  });
@@ -196,11 +195,13 @@ function inputFieldDefaultValueChanged(input, oldField, newField) {
196
195
  inputName: input.name,
197
196
  inputFieldName: newField.name,
198
197
  };
199
- if (oldField.defaultValue !== undefined) {
200
- meta.oldDefaultValue = (0, string_js_1.safeString)(oldField.defaultValue);
198
+ const oldDefaultValue = (0, graphql_js_1.getDefaultValue)(oldField);
199
+ const newDefaultValue = (0, graphql_js_1.getDefaultValue)(newField);
200
+ if (oldDefaultValue !== undefined) {
201
+ meta.oldDefaultValue = (0, string_js_1.safeString)(oldDefaultValue);
201
202
  }
202
- if (newField.defaultValue !== undefined) {
203
- meta.newDefaultValue = (0, string_js_1.safeString)(newField.defaultValue);
203
+ if (newDefaultValue !== undefined) {
204
+ meta.newDefaultValue = (0, string_js_1.safeString)(newDefaultValue);
204
205
  }
205
206
  return inputFieldDefaultValueChangedFromMeta({
206
207
  type: change_js_1.ChangeType.InputFieldDefaultValueChanged,
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.changesInDirective = changesInDirective;
4
4
  const compare_js_1 = require("../utils/compare.js");
5
+ const graphql_js_1 = require("../utils/graphql.js");
5
6
  const directive_js_1 = require("./changes/directive.js");
6
7
  function changesInDirective(oldDirective, newDirective, addChange) {
7
8
  if ((0, compare_js_1.isNotEqual)(oldDirective?.description, newDirective.description)) {
@@ -41,7 +42,7 @@ function changesInDirectiveArgument(directive, oldArg, newArg, addChange) {
41
42
  if ((0, compare_js_1.isNotEqual)(oldArg?.description, newArg.description)) {
42
43
  addChange((0, directive_js_1.directiveArgumentDescriptionChanged)(directive, oldArg, newArg));
43
44
  }
44
- if ((0, compare_js_1.isNotEqual)(oldArg?.defaultValue, newArg.defaultValue)) {
45
+ if (!(0, graphql_js_1.defaultValuesAreEqual)(oldArg, newArg)) {
45
46
  addChange((0, directive_js_1.directiveArgumentDefaultValueChanged)(directive, oldArg, newArg));
46
47
  }
47
48
  if ((0, compare_js_1.isNotEqual)(oldArg.type.toString(), newArg.type.toString())) {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.changesInInputObject = changesInInputObject;
4
4
  const graphql_1 = require("graphql");
5
5
  const compare_js_1 = require("../utils/compare.js");
6
+ const graphql_js_1 = require("../utils/graphql.js");
6
7
  const directive_usage_js_1 = require("./changes/directive-usage.js");
7
8
  const input_js_1 = require("./changes/input.js");
8
9
  function changesInInputObject(oldInput, newInput, addChange) {
@@ -46,22 +47,15 @@ function changesInInputField(input, oldField, newField, addChange) {
46
47
  }
47
48
  }
48
49
  if (!(0, compare_js_1.isVoid)(oldField)) {
49
- if ((0, compare_js_1.isNotEqual)(oldField?.defaultValue, newField.defaultValue)) {
50
- if (Array.isArray(oldField?.defaultValue) && Array.isArray(newField.defaultValue)) {
51
- if ((0, compare_js_1.diffArrays)(oldField.defaultValue, newField.defaultValue).length > 0) {
52
- addChange((0, input_js_1.inputFieldDefaultValueChanged)(input, oldField, newField));
53
- }
54
- }
55
- else if (JSON.stringify(oldField?.defaultValue) !== JSON.stringify(newField.defaultValue)) {
56
- addChange((0, input_js_1.inputFieldDefaultValueChanged)(input, oldField, newField));
57
- }
50
+ if (!(0, graphql_js_1.defaultValuesAreEqual)(oldField, newField)) {
51
+ addChange((0, input_js_1.inputFieldDefaultValueChanged)(input, oldField, newField));
58
52
  }
59
53
  if (!(0, compare_js_1.isVoid)(oldField) && (0, compare_js_1.isNotEqual)(oldField.type.toString(), newField.type.toString())) {
60
54
  addChange((0, input_js_1.inputFieldTypeChanged)(input, oldField, newField));
61
55
  }
62
56
  }
63
- if (newField.astNode?.directives) {
64
- (0, compare_js_1.compareDirectiveLists)(oldField?.astNode?.directives || [], newField.astNode.directives || [], {
57
+ if (oldField?.astNode?.directives || newField.astNode?.directives) {
58
+ (0, compare_js_1.compareDirectiveLists)(oldField?.astNode?.directives || [], newField.astNode?.directives || [], {
65
59
  onAdded(directive) {
66
60
  addChange((0, directive_usage_js_1.directiveUsageAdded)(graphql_1.Kind.INPUT_VALUE_DEFINITION, directive, {
67
61
  type: input,
@@ -1,5 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultValue = getDefaultValue;
4
+ exports.hasDefaultValue = hasDefaultValue;
5
+ exports.defaultValuesAreEqual = defaultValuesAreEqual;
3
6
  exports.safeChangeForField = safeChangeForField;
4
7
  exports.safeChangeForInputValue = safeChangeForInputValue;
5
8
  exports.getKind = getKind;
@@ -12,6 +15,43 @@ exports.removeDirectives = removeDirectives;
12
15
  exports.getReachableTypes = getReachableTypes;
13
16
  const graphql_1 = require("graphql");
14
17
  const is_deprecated_js_1 = require("./is-deprecated.js");
18
+ function getDefaultValue(inputValue) {
19
+ if (inputValue.default !== undefined) {
20
+ if (inputValue.default.literal !== undefined) {
21
+ return (0, graphql_1.valueFromAST)(inputValue.default.literal, inputValue.type);
22
+ }
23
+ return (0, graphql_1.coerceInputValue)(inputValue.default.value, inputValue.type);
24
+ }
25
+ return inputValue.defaultValue;
26
+ }
27
+ function hasDefaultValue(inputValue) {
28
+ return inputValue.default !== undefined || inputValue.defaultValue !== undefined;
29
+ }
30
+ function defaultValuesAreEqual(oldInputValue, newInputValue) {
31
+ return defaultValueEquals(oldInputValue == null ? undefined : getDefaultValue(oldInputValue), getDefaultValue(newInputValue));
32
+ }
33
+ function defaultValueEquals(oldValue, newValue) {
34
+ if (Object.is(oldValue, newValue)) {
35
+ return true;
36
+ }
37
+ if (Array.isArray(oldValue) && Array.isArray(newValue)) {
38
+ return (oldValue.length === newValue.length &&
39
+ oldValue.every((value, index) => defaultValueEquals(value, newValue[index])));
40
+ }
41
+ if (oldValue !== null &&
42
+ newValue !== null &&
43
+ typeof oldValue === 'object' &&
44
+ typeof newValue === 'object') {
45
+ const oldRecord = oldValue;
46
+ const newRecord = newValue;
47
+ const oldKeys = Object.keys(oldRecord);
48
+ const newKeys = Object.keys(newRecord);
49
+ return (oldKeys.length === newKeys.length &&
50
+ oldKeys.every(key => Object.prototype.hasOwnProperty.call(newRecord, key) &&
51
+ defaultValueEquals(oldRecord[key], newRecord[key])));
52
+ }
53
+ return false;
54
+ }
15
55
  function safeChangeForField(oldType, newType) {
16
56
  if (!(0, graphql_1.isWrappingType)(oldType) && !(0, graphql_1.isWrappingType)(newType)) {
17
57
  return oldType.toString() === newType.toString();
@@ -81,7 +121,7 @@ function findDeprecatedUsages(schema, ast) {
81
121
  if (reason) {
82
122
  const fieldDef = typeInfo.getFieldDef();
83
123
  if (fieldDef) {
84
- errors.push(new graphql_1.GraphQLError(`The argument '${argument?.name}' of '${fieldDef.name}' is deprecated. ${reason}`, [node]));
124
+ errors.push(new graphql_1.GraphQLError(`The argument '${argument?.name}' of '${fieldDef.name}' is deprecated. ${reason}`, { nodes: [node] }));
85
125
  }
86
126
  }
87
127
  }
@@ -92,7 +132,7 @@ function findDeprecatedUsages(schema, ast) {
92
132
  const parentType = typeInfo.getParentType();
93
133
  if (parentType) {
94
134
  const reason = fieldDef.deprecationReason;
95
- errors.push(new graphql_1.GraphQLError(`The field '${parentType.name}.${fieldDef.name}' is deprecated.${reason ? ' ' + reason : ''}`, [node]));
135
+ errors.push(new graphql_1.GraphQLError(`The field '${parentType.name}.${fieldDef.name}' is deprecated.${reason ? ' ' + reason : ''}`, { nodes: [node] }));
96
136
  }
97
137
  }
98
138
  },
@@ -102,7 +142,7 @@ function findDeprecatedUsages(schema, ast) {
102
142
  const type = (0, graphql_1.getNamedType)(typeInfo.getInputType());
103
143
  if (type) {
104
144
  const reason = enumVal.deprecationReason;
105
- errors.push(new graphql_1.GraphQLError(`The enum value '${type.name}.${enumVal.name}' is deprecated.${reason ? ' ' + reason : ''}`, [node]));
145
+ errors.push(new graphql_1.GraphQLError(`The enum value '${type.name}.${enumVal.name}' is deprecated.${reason ? ' ' + reason : ''}`, { nodes: [node] }));
106
146
  }
107
147
  }
108
148
  },
@@ -11,7 +11,11 @@ function validateAliasCount({ source, doc, maxAliasCount, fragmentGraph, }) {
11
11
  }
12
12
  const aliasCount = countAliases(definition, getFragmentByFragmentName);
13
13
  if (aliasCount > maxAliasCount) {
14
- return new graphql_1.GraphQLError(`Too many aliases (${aliasCount}). Maximum allowed is ${maxAliasCount}`, [definition], source, definition.loc?.start ? [definition.loc.start] : undefined);
14
+ return new graphql_1.GraphQLError(`Too many aliases (${aliasCount}). Maximum allowed is ${maxAliasCount}`, {
15
+ source,
16
+ nodes: [definition],
17
+ positions: definition.loc?.start ? [definition.loc.start] : undefined,
18
+ });
15
19
  }
16
20
  }
17
21
  }
@@ -11,7 +11,11 @@ function validateComplexity({ source, doc, maxComplexityScore, config, fragmentG
11
11
  }
12
12
  const complexityScore = calculateOperationComplexity(definition, config, getFragmentByFragmentName);
13
13
  if (complexityScore > maxComplexityScore) {
14
- return new graphql_1.GraphQLError(`Too high complexity score (${complexityScore}). Maximum allowed is ${maxComplexityScore}`, [definition], source, definition.loc?.start ? [definition.loc.start] : undefined);
14
+ return new graphql_1.GraphQLError(`Too high complexity score (${complexityScore}). Maximum allowed is ${maxComplexityScore}`, {
15
+ nodes: [definition],
16
+ positions: definition.loc?.start ? [definition.loc.start] : undefined,
17
+ source,
18
+ });
15
19
  }
16
20
  }
17
21
  }
@@ -11,7 +11,11 @@ function validateDirectiveCount({ source, doc, maxDirectiveCount, fragmentGraph,
11
11
  }
12
12
  const directiveCount = countDirectives(definition, getFragmentByFragmentName);
13
13
  if (directiveCount > maxDirectiveCount) {
14
- return new graphql_1.GraphQLError(`Too many directives (${directiveCount}). Maximum allowed is ${maxDirectiveCount}`, [definition], source, definition.loc?.start ? [definition.loc.start] : undefined);
14
+ return new graphql_1.GraphQLError(`Too many directives (${directiveCount}). Maximum allowed is ${maxDirectiveCount}`, {
15
+ nodes: [definition],
16
+ source,
17
+ positions: definition.loc?.start ? [definition.loc.start] : undefined,
18
+ });
15
19
  }
16
20
  }
17
21
  }
@@ -20,7 +20,11 @@ function validateQueryDepth({ source, doc, maxDepth, fragmentGraph, }) {
20
20
  throw errorOrNode;
21
21
  }
22
22
  const node = errorOrNode;
23
- return new graphql_1.GraphQLError(`Query exceeds maximum depth of ${maxDepth}`, node, source, node.loc?.start ? [node.loc.start] : undefined);
23
+ return new graphql_1.GraphQLError(`Query exceeds maximum depth of ${maxDepth}`, {
24
+ nodes: node,
25
+ source,
26
+ positions: node.loc?.start ? [node.loc.start] : undefined,
27
+ });
24
28
  }
25
29
  }
26
30
  function calculateDepth({ node, currentDepth, maxDepth, getFragment, }) {
@@ -48,6 +48,10 @@ function calculateTokenCount(args) {
48
48
  function validateTokenCount(args) {
49
49
  const tokenCount = calculateTokenCount(args);
50
50
  if (tokenCount > args.maxTokenCount) {
51
- return new graphql_1.GraphQLError(`Query exceeds maximum token count of ${args.maxTokenCount} (actual: ${tokenCount})`, args.document, args.source, args.document.loc?.start ? [args.document.loc.start] : undefined);
51
+ return new graphql_1.GraphQLError(`Query exceeds maximum token count of ${args.maxTokenCount} (actual: ${tokenCount})`, {
52
+ nodes: args.document,
53
+ source: args.source,
54
+ positions: args.document.loc?.start ? [args.document.loc.start] : undefined,
55
+ });
52
56
  }
53
57
  }
@@ -1,8 +1,5 @@
1
1
  import * as core from '@actions/core';
2
2
  import { run } from './run.js';
3
- global.navigator = {
4
- userAgent: 'node.js',
5
- };
6
3
  run().catch(e => {
7
4
  core.setFailed(e.message || e);
8
5
  });
@@ -72,7 +72,11 @@ export async function run() {
72
72
  }
73
73
  let config;
74
74
  if (onUsage) {
75
- const checkUsage = require(onUsage);
75
+ // real runtime require so ncc doesn't try to resolve it from the bundle
76
+ const checkUsage = process
77
+ // @ts-expect-error getBuiltinModule exists starting node v20.16.0
78
+ .getBuiltinModule('module')
79
+ .createRequire(import.meta.url)(onUsage);
76
80
  if (checkUsage) {
77
81
  config = {
78
82
  checkUsage,
@@ -41,7 +41,12 @@ export function getInputAsArray(name, options) {
41
41
  export function resolveRule(name) {
42
42
  const filepath = ensureAbsolute(name);
43
43
  if (existsSync(filepath)) {
44
- return require(filepath);
44
+ // ncc rewrites bare require to its bundler require, which can't load files
45
+ // outside the bundle. createRequire gives us a real runtime require.
46
+ return (process
47
+ // @ts-expect-error getBuiltinModule exists starting node v20.16.0
48
+ .getBuiltinModule('module')
49
+ .createRequire(import.meta.url)(filepath));
45
50
  }
46
51
  return DiffRule[name];
47
52
  }
@@ -1,27 +1,20 @@
1
1
  import { Kind, } from 'graphql';
2
- import { compareDirectiveLists, diffArrays, isNotEqual } from '../utils/compare.js';
2
+ import { compareDirectiveLists, isNotEqual } from '../utils/compare.js';
3
+ import { defaultValuesAreEqual } from '../utils/graphql.js';
3
4
  import { fieldArgumentDefaultChanged, fieldArgumentDescriptionChanged, fieldArgumentTypeChanged, } from './changes/argument.js';
4
5
  import { directiveUsageAdded, directiveUsageChanged, directiveUsageRemoved, } from './changes/directive-usage.js';
5
6
  export function changesInArgument(type, field, oldArg, newArg, addChange) {
6
7
  if (isNotEqual(oldArg?.description, newArg.description)) {
7
8
  addChange(fieldArgumentDescriptionChanged(type, field, oldArg, newArg));
8
9
  }
9
- if (isNotEqual(oldArg?.defaultValue, newArg.defaultValue)) {
10
- if (Array.isArray(oldArg?.defaultValue) && Array.isArray(newArg.defaultValue)) {
11
- const diff = diffArrays(oldArg.defaultValue, newArg.defaultValue);
12
- if (diff.length > 0) {
13
- addChange(fieldArgumentDefaultChanged(type, field, oldArg, newArg));
14
- }
15
- }
16
- else if (JSON.stringify(oldArg?.defaultValue) !== JSON.stringify(newArg.defaultValue)) {
17
- addChange(fieldArgumentDefaultChanged(type, field, oldArg, newArg));
18
- }
10
+ if (!defaultValuesAreEqual(oldArg, newArg)) {
11
+ addChange(fieldArgumentDefaultChanged(type, field, oldArg, newArg));
19
12
  }
20
13
  if (isNotEqual(oldArg?.type.toString(), newArg.type.toString())) {
21
14
  addChange(fieldArgumentTypeChanged(type, field, oldArg, newArg));
22
15
  }
23
- if (newArg.astNode?.directives) {
24
- compareDirectiveLists(oldArg?.astNode?.directives || [], newArg.astNode.directives || [], {
16
+ if (oldArg?.astNode?.directives || newArg.astNode?.directives) {
17
+ compareDirectiveLists(oldArg?.astNode?.directives || [], newArg.astNode?.directives || [], {
25
18
  onAdded(directive) {
26
19
  addChange(directiveUsageAdded(Kind.ARGUMENT, directive, {
27
20
  argument: newArg,
@@ -1,4 +1,4 @@
1
- import { safeChangeForInputValue } from '../../utils/graphql.js';
1
+ import { getDefaultValue, safeChangeForInputValue } from '../../utils/graphql.js';
2
2
  import { fmt, safeString } from '../../utils/string.js';
3
3
  import { ChangeType, CriticalityLevel, } from './change.js';
4
4
  function buildFieldArgumentDescriptionChangedMessage(args) {
@@ -57,11 +57,13 @@ export function fieldArgumentDefaultChanged(type, field, oldArg, newArg) {
57
57
  fieldName: field.name,
58
58
  argumentName: newArg.name,
59
59
  };
60
- if (oldArg?.defaultValue !== undefined) {
61
- meta.oldDefaultValue = safeString(oldArg.defaultValue);
60
+ const oldDefaultValue = oldArg === null ? undefined : getDefaultValue(oldArg);
61
+ const newDefaultValue = getDefaultValue(newArg);
62
+ if (oldDefaultValue !== undefined) {
63
+ meta.oldDefaultValue = safeString(oldDefaultValue);
62
64
  }
63
- if (newArg.defaultValue !== undefined) {
64
- meta.newDefaultValue = safeString(newArg.defaultValue);
65
+ if (newDefaultValue !== undefined) {
66
+ meta.newDefaultValue = safeString(newDefaultValue);
65
67
  }
66
68
  return fieldArgumentDefaultChangedFromMeta({
67
69
  type: ChangeType.FieldArgumentDefaultChanged,
@@ -1,5 +1,5 @@
1
1
  import { isNonNullType } from 'graphql';
2
- import { safeChangeForInputValue } from '../../utils/graphql.js';
2
+ import { getDefaultValue, hasDefaultValue, safeChangeForInputValue } from '../../utils/graphql.js';
3
3
  import { fmt, safeString } from '../../utils/string.js';
4
4
  import { ChangeType, CriticalityLevel, } from './change.js';
5
5
  function buildDirectiveRemovedMessage(args) {
@@ -205,7 +205,9 @@ export function directiveArgumentAdded(directive, arg, addedToNewDirective) {
205
205
  directiveName: directive.name,
206
206
  addedDirectiveArgumentName: arg.name,
207
207
  addedDirectiveArgumentType: arg.type.toString(),
208
- addedDirectiveDefaultValue: arg.defaultValue === undefined ? undefined : safeString(arg.defaultValue),
208
+ addedDirectiveDefaultValue: hasDefaultValue(arg)
209
+ ? safeString(getDefaultValue(arg))
210
+ : undefined,
209
211
  addedDirectiveArgumentTypeIsNonNull: isNonNullType(arg.type),
210
212
  addedDirectiveArgumentDescription: arg.description ?? undefined,
211
213
  addedToNewDirective,
@@ -293,11 +295,13 @@ export function directiveArgumentDefaultValueChanged(directive, oldArg, newArg)
293
295
  directiveName: directive.name,
294
296
  directiveArgumentName: newArg.name,
295
297
  };
296
- if (oldArg?.defaultValue !== undefined) {
297
- meta.oldDirectiveArgumentDefaultValue = safeString(oldArg.defaultValue);
298
+ const oldDefaultValue = oldArg === null ? undefined : getDefaultValue(oldArg);
299
+ const newDefaultValue = getDefaultValue(newArg);
300
+ if (oldDefaultValue !== undefined) {
301
+ meta.oldDirectiveArgumentDefaultValue = safeString(oldDefaultValue);
298
302
  }
299
- if (newArg.defaultValue !== undefined) {
300
- meta.newDirectiveArgumentDefaultValue = safeString(newArg.defaultValue);
303
+ if (newDefaultValue !== undefined) {
304
+ meta.newDirectiveArgumentDefaultValue = safeString(newDefaultValue);
301
305
  }
302
306
  return directiveArgumentDefaultValueChangedFromMeta({
303
307
  type: ChangeType.DirectiveArgumentDefaultValueChanged,
@@ -1,5 +1,5 @@
1
1
  import { GraphQLDeprecatedDirective, isInterfaceType, isNonNullType, } from 'graphql';
2
- import { safeChangeForField } from '../../utils/graphql.js';
2
+ import { hasDefaultValue, safeChangeForField } from '../../utils/graphql.js';
3
3
  import { fmt } from '../../utils/string.js';
4
4
  import { ChangeType, CriticalityLevel, } from './change.js';
5
5
  function buildFieldRemovedMessage(args) {
@@ -299,7 +299,8 @@ export function fieldArgumentAddedFromMeta(args) {
299
299
  };
300
300
  }
301
301
  export function fieldArgumentAdded(type, field, arg, addedToNewField) {
302
- const isBreaking = isNonNullType(arg.type) && typeof arg.defaultValue === 'undefined';
302
+ const hasDefault = hasDefaultValue(arg);
303
+ const isBreaking = isNonNullType(arg.type) && !hasDefault;
303
304
  return fieldArgumentAddedFromMeta({
304
305
  type: ChangeType.FieldArgumentAdded,
305
306
  meta: {
@@ -307,7 +308,7 @@ export function fieldArgumentAdded(type, field, arg, addedToNewField) {
307
308
  fieldName: field.name,
308
309
  addedArgumentName: arg.name,
309
310
  addedArgumentType: arg.type.toString(),
310
- hasDefaultValue: arg.defaultValue != null,
311
+ hasDefaultValue: hasDefault,
311
312
  addedToNewField,
312
313
  isAddedFieldArgumentBreaking: isBreaking,
313
314
  },
@@ -1,5 +1,5 @@
1
1
  import { isNonNullType } from 'graphql';
2
- import { safeChangeForInputValue } from '../../utils/graphql.js';
2
+ import { getDefaultValue, hasDefaultValue, safeChangeForInputValue } from '../../utils/graphql.js';
3
3
  import { isDeprecated } from '../../utils/is-deprecated.js';
4
4
  import { fmt, safeString } from '../../utils/string.js';
5
5
  import { ChangeType, CriticalityLevel, } from './change.js';
@@ -67,6 +67,7 @@ export function inputFieldAddedFromMeta(args) {
67
67
  };
68
68
  }
69
69
  export function inputFieldAdded(input, field, addedToNewType) {
70
+ const defaultValue = getDefaultValue(field);
70
71
  return inputFieldAddedFromMeta({
71
72
  type: ChangeType.InputFieldAdded,
72
73
  meta: {
@@ -74,9 +75,7 @@ export function inputFieldAdded(input, field, addedToNewType) {
74
75
  addedInputFieldName: field.name,
75
76
  isAddedInputFieldTypeNullable: !isNonNullType(field.type),
76
77
  addedInputFieldType: field.type.toString(),
77
- ...(field.defaultValue === undefined
78
- ? {}
79
- : { addedFieldDefault: safeString(field.defaultValue) }),
78
+ ...(hasDefaultValue(field) ? { addedFieldDefault: safeString(defaultValue) } : {}),
80
79
  addedToNewType,
81
80
  },
82
81
  });
@@ -179,11 +178,13 @@ export function inputFieldDefaultValueChanged(input, oldField, newField) {
179
178
  inputName: input.name,
180
179
  inputFieldName: newField.name,
181
180
  };
182
- if (oldField.defaultValue !== undefined) {
183
- meta.oldDefaultValue = safeString(oldField.defaultValue);
181
+ const oldDefaultValue = getDefaultValue(oldField);
182
+ const newDefaultValue = getDefaultValue(newField);
183
+ if (oldDefaultValue !== undefined) {
184
+ meta.oldDefaultValue = safeString(oldDefaultValue);
184
185
  }
185
- if (newField.defaultValue !== undefined) {
186
- meta.newDefaultValue = safeString(newField.defaultValue);
186
+ if (newDefaultValue !== undefined) {
187
+ meta.newDefaultValue = safeString(newDefaultValue);
187
188
  }
188
189
  return inputFieldDefaultValueChangedFromMeta({
189
190
  type: ChangeType.InputFieldDefaultValueChanged,
@@ -1,4 +1,5 @@
1
1
  import { compareLists, diffArrays, isNotEqual } from '../utils/compare.js';
2
+ import { defaultValuesAreEqual } from '../utils/graphql.js';
2
3
  import { directiveArgumentAdded, directiveArgumentDefaultValueChanged, directiveArgumentDescriptionChanged, directiveArgumentRemoved, directiveArgumentTypeChanged, directiveDescriptionChanged, directiveLocationAdded, directiveLocationRemoved, directiveRepeatableAdded, directiveRepeatableRemoved, } from './changes/directive.js';
3
4
  export function changesInDirective(oldDirective, newDirective, addChange) {
4
5
  if (isNotEqual(oldDirective?.description, newDirective.description)) {
@@ -38,7 +39,7 @@ function changesInDirectiveArgument(directive, oldArg, newArg, addChange) {
38
39
  if (isNotEqual(oldArg?.description, newArg.description)) {
39
40
  addChange(directiveArgumentDescriptionChanged(directive, oldArg, newArg));
40
41
  }
41
- if (isNotEqual(oldArg?.defaultValue, newArg.defaultValue)) {
42
+ if (!defaultValuesAreEqual(oldArg, newArg)) {
42
43
  addChange(directiveArgumentDefaultValueChanged(directive, oldArg, newArg));
43
44
  }
44
45
  if (isNotEqual(oldArg.type.toString(), newArg.type.toString())) {
@@ -1,5 +1,6 @@
1
1
  import { Kind } from 'graphql';
2
- import { compareDirectiveLists, compareLists, diffArrays, isNotEqual, isVoid, } from '../utils/compare.js';
2
+ import { compareDirectiveLists, compareLists, isNotEqual, isVoid } from '../utils/compare.js';
3
+ import { defaultValuesAreEqual } from '../utils/graphql.js';
3
4
  import { directiveUsageAdded, directiveUsageChanged, directiveUsageRemoved, } from './changes/directive-usage.js';
4
5
  import { inputFieldAdded, inputFieldDefaultValueChanged, inputFieldDescriptionAdded, inputFieldDescriptionChanged, inputFieldDescriptionRemoved, inputFieldRemoved, inputFieldTypeChanged, } from './changes/input.js';
5
6
  export function changesInInputObject(oldInput, newInput, addChange) {
@@ -43,22 +44,15 @@ function changesInInputField(input, oldField, newField, addChange) {
43
44
  }
44
45
  }
45
46
  if (!isVoid(oldField)) {
46
- if (isNotEqual(oldField?.defaultValue, newField.defaultValue)) {
47
- if (Array.isArray(oldField?.defaultValue) && Array.isArray(newField.defaultValue)) {
48
- if (diffArrays(oldField.defaultValue, newField.defaultValue).length > 0) {
49
- addChange(inputFieldDefaultValueChanged(input, oldField, newField));
50
- }
51
- }
52
- else if (JSON.stringify(oldField?.defaultValue) !== JSON.stringify(newField.defaultValue)) {
53
- addChange(inputFieldDefaultValueChanged(input, oldField, newField));
54
- }
47
+ if (!defaultValuesAreEqual(oldField, newField)) {
48
+ addChange(inputFieldDefaultValueChanged(input, oldField, newField));
55
49
  }
56
50
  if (!isVoid(oldField) && isNotEqual(oldField.type.toString(), newField.type.toString())) {
57
51
  addChange(inputFieldTypeChanged(input, oldField, newField));
58
52
  }
59
53
  }
60
- if (newField.astNode?.directives) {
61
- compareDirectiveLists(oldField?.astNode?.directives || [], newField.astNode.directives || [], {
54
+ if (oldField?.astNode?.directives || newField.astNode?.directives) {
55
+ compareDirectiveLists(oldField?.astNode?.directives || [], newField.astNode?.directives || [], {
62
56
  onAdded(directive) {
63
57
  addChange(directiveUsageAdded(Kind.INPUT_VALUE_DEFINITION, directive, {
64
58
  type: input,
@@ -1,5 +1,42 @@
1
- import { getNamedType, GraphQLError, isInputObjectType, isInterfaceType, isListType, isNonNullType, isObjectType, isScalarType, isUnionType, isWrappingType, Kind, TypeInfo, visit, visitWithTypeInfo, } from 'graphql';
1
+ import { coerceInputValue, getNamedType, GraphQLError, isInputObjectType, isInterfaceType, isListType, isNonNullType, isObjectType, isScalarType, isUnionType, isWrappingType, Kind, TypeInfo, valueFromAST, visit, visitWithTypeInfo, } from 'graphql';
2
2
  import { isDeprecated } from './is-deprecated.js';
3
+ export function getDefaultValue(inputValue) {
4
+ if (inputValue.default !== undefined) {
5
+ if (inputValue.default.literal !== undefined) {
6
+ return valueFromAST(inputValue.default.literal, inputValue.type);
7
+ }
8
+ return coerceInputValue(inputValue.default.value, inputValue.type);
9
+ }
10
+ return inputValue.defaultValue;
11
+ }
12
+ export function hasDefaultValue(inputValue) {
13
+ return inputValue.default !== undefined || inputValue.defaultValue !== undefined;
14
+ }
15
+ export function defaultValuesAreEqual(oldInputValue, newInputValue) {
16
+ return defaultValueEquals(oldInputValue == null ? undefined : getDefaultValue(oldInputValue), getDefaultValue(newInputValue));
17
+ }
18
+ function defaultValueEquals(oldValue, newValue) {
19
+ if (Object.is(oldValue, newValue)) {
20
+ return true;
21
+ }
22
+ if (Array.isArray(oldValue) && Array.isArray(newValue)) {
23
+ return (oldValue.length === newValue.length &&
24
+ oldValue.every((value, index) => defaultValueEquals(value, newValue[index])));
25
+ }
26
+ if (oldValue !== null &&
27
+ newValue !== null &&
28
+ typeof oldValue === 'object' &&
29
+ typeof newValue === 'object') {
30
+ const oldRecord = oldValue;
31
+ const newRecord = newValue;
32
+ const oldKeys = Object.keys(oldRecord);
33
+ const newKeys = Object.keys(newRecord);
34
+ return (oldKeys.length === newKeys.length &&
35
+ oldKeys.every(key => Object.prototype.hasOwnProperty.call(newRecord, key) &&
36
+ defaultValueEquals(oldRecord[key], newRecord[key])));
37
+ }
38
+ return false;
39
+ }
3
40
  export function safeChangeForField(oldType, newType) {
4
41
  if (!isWrappingType(oldType) && !isWrappingType(newType)) {
5
42
  return oldType.toString() === newType.toString();
@@ -69,7 +106,7 @@ export function findDeprecatedUsages(schema, ast) {
69
106
  if (reason) {
70
107
  const fieldDef = typeInfo.getFieldDef();
71
108
  if (fieldDef) {
72
- errors.push(new GraphQLError(`The argument '${argument?.name}' of '${fieldDef.name}' is deprecated. ${reason}`, [node]));
109
+ errors.push(new GraphQLError(`The argument '${argument?.name}' of '${fieldDef.name}' is deprecated. ${reason}`, { nodes: [node] }));
73
110
  }
74
111
  }
75
112
  }
@@ -80,7 +117,7 @@ export function findDeprecatedUsages(schema, ast) {
80
117
  const parentType = typeInfo.getParentType();
81
118
  if (parentType) {
82
119
  const reason = fieldDef.deprecationReason;
83
- errors.push(new GraphQLError(`The field '${parentType.name}.${fieldDef.name}' is deprecated.${reason ? ' ' + reason : ''}`, [node]));
120
+ errors.push(new GraphQLError(`The field '${parentType.name}.${fieldDef.name}' is deprecated.${reason ? ' ' + reason : ''}`, { nodes: [node] }));
84
121
  }
85
122
  }
86
123
  },
@@ -90,7 +127,7 @@ export function findDeprecatedUsages(schema, ast) {
90
127
  const type = getNamedType(typeInfo.getInputType());
91
128
  if (type) {
92
129
  const reason = enumVal.deprecationReason;
93
- errors.push(new GraphQLError(`The enum value '${type.name}.${enumVal.name}' is deprecated.${reason ? ' ' + reason : ''}`, [node]));
130
+ errors.push(new GraphQLError(`The enum value '${type.name}.${enumVal.name}' is deprecated.${reason ? ' ' + reason : ''}`, { nodes: [node] }));
94
131
  }
95
132
  }
96
133
  },
@@ -7,7 +7,11 @@ export function validateAliasCount({ source, doc, maxAliasCount, fragmentGraph,
7
7
  }
8
8
  const aliasCount = countAliases(definition, getFragmentByFragmentName);
9
9
  if (aliasCount > maxAliasCount) {
10
- return new GraphQLError(`Too many aliases (${aliasCount}). Maximum allowed is ${maxAliasCount}`, [definition], source, definition.loc?.start ? [definition.loc.start] : undefined);
10
+ return new GraphQLError(`Too many aliases (${aliasCount}). Maximum allowed is ${maxAliasCount}`, {
11
+ source,
12
+ nodes: [definition],
13
+ positions: definition.loc?.start ? [definition.loc.start] : undefined,
14
+ });
11
15
  }
12
16
  }
13
17
  }
@@ -7,7 +7,11 @@ export function validateComplexity({ source, doc, maxComplexityScore, config, fr
7
7
  }
8
8
  const complexityScore = calculateOperationComplexity(definition, config, getFragmentByFragmentName);
9
9
  if (complexityScore > maxComplexityScore) {
10
- return new GraphQLError(`Too high complexity score (${complexityScore}). Maximum allowed is ${maxComplexityScore}`, [definition], source, definition.loc?.start ? [definition.loc.start] : undefined);
10
+ return new GraphQLError(`Too high complexity score (${complexityScore}). Maximum allowed is ${maxComplexityScore}`, {
11
+ nodes: [definition],
12
+ positions: definition.loc?.start ? [definition.loc.start] : undefined,
13
+ source,
14
+ });
11
15
  }
12
16
  }
13
17
  }
@@ -7,7 +7,11 @@ export function validateDirectiveCount({ source, doc, maxDirectiveCount, fragmen
7
7
  }
8
8
  const directiveCount = countDirectives(definition, getFragmentByFragmentName);
9
9
  if (directiveCount > maxDirectiveCount) {
10
- return new GraphQLError(`Too many directives (${directiveCount}). Maximum allowed is ${maxDirectiveCount}`, [definition], source, definition.loc?.start ? [definition.loc.start] : undefined);
10
+ return new GraphQLError(`Too many directives (${directiveCount}). Maximum allowed is ${maxDirectiveCount}`, {
11
+ nodes: [definition],
12
+ source,
13
+ positions: definition.loc?.start ? [definition.loc.start] : undefined,
14
+ });
11
15
  }
12
16
  }
13
17
  }
@@ -15,7 +15,11 @@ export function validateQueryDepth({ source, doc, maxDepth, fragmentGraph, }) {
15
15
  throw errorOrNode;
16
16
  }
17
17
  const node = errorOrNode;
18
- return new GraphQLError(`Query exceeds maximum depth of ${maxDepth}`, node, source, node.loc?.start ? [node.loc.start] : undefined);
18
+ return new GraphQLError(`Query exceeds maximum depth of ${maxDepth}`, {
19
+ nodes: node,
20
+ source,
21
+ positions: node.loc?.start ? [node.loc.start] : undefined,
22
+ });
19
23
  }
20
24
  }
21
25
  export function calculateDepth({ node, currentDepth, maxDepth, getFragment, }) {
@@ -44,6 +44,10 @@ export function calculateTokenCount(args) {
44
44
  export function validateTokenCount(args) {
45
45
  const tokenCount = calculateTokenCount(args);
46
46
  if (tokenCount > args.maxTokenCount) {
47
- return new GraphQLError(`Query exceeds maximum token count of ${args.maxTokenCount} (actual: ${tokenCount})`, args.document, args.source, args.document.loc?.start ? [args.document.loc.start] : undefined);
47
+ return new GraphQLError(`Query exceeds maximum token count of ${args.maxTokenCount} (actual: ${tokenCount})`, {
48
+ nodes: args.document,
49
+ source: args.source,
50
+ positions: args.document.loc?.start ? [args.document.loc.start] : undefined,
51
+ });
48
52
  }
49
53
  }
package/package.json CHANGED
@@ -1,32 +1,32 @@
1
1
  {
2
2
  "name": "@graphql-inspector/cli",
3
- "version": "6.0.8",
3
+ "version": "7.0.0",
4
4
  "description": "Tooling for GraphQL. Compare GraphQL Schemas, check documents, find breaking changes, find similar types.",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
- "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
7
+ "graphql": "^16.0.0 || ^17.0.0"
8
8
  },
9
9
  "dependencies": {
10
- "@babel/core": "7.26.10",
11
- "tslib": "2.6.2",
12
- "yargs": "17.7.2",
13
- "@graphql-inspector/audit-command": "5.0.20",
14
- "@graphql-inspector/code-loader": "5.0.1",
15
- "@graphql-inspector/config": "4.0.2",
16
- "@graphql-inspector/commands": "6.0.0",
17
- "@graphql-inspector/coverage-command": "6.1.14",
18
- "@graphql-inspector/diff-command": "6.0.8",
19
- "@graphql-inspector/docs-command": "5.0.5",
20
- "@graphql-inspector/github-loader": "5.0.1",
21
- "@graphql-inspector/git-loader": "5.0.1",
22
- "@graphql-inspector/introspect-command": "5.0.20",
23
- "@graphql-inspector/graphql-loader": "5.0.1",
24
- "@graphql-inspector/json-loader": "5.0.1",
25
- "@graphql-inspector/loaders": "4.1.0",
26
- "@graphql-inspector/serve-command": "5.0.7",
27
- "@graphql-inspector/url-loader": "5.0.1",
28
- "@graphql-inspector/validate-command": "5.0.20",
29
- "@graphql-inspector/similar-command": "5.0.20"
10
+ "@babel/core": "^7.26.10",
11
+ "tslib": "~2.6.2",
12
+ "yargs": "^17.7.2",
13
+ "@graphql-inspector/audit-command": "^6.0.0",
14
+ "@graphql-inspector/code-loader": "^6.0.0",
15
+ "@graphql-inspector/commands": "^7.0.0",
16
+ "@graphql-inspector/config": "^5.0.0",
17
+ "@graphql-inspector/coverage-command": "^7.0.0",
18
+ "@graphql-inspector/diff-command": "^7.0.0",
19
+ "@graphql-inspector/docs-command": "^6.0.0",
20
+ "@graphql-inspector/git-loader": "^6.0.0",
21
+ "@graphql-inspector/github-loader": "^6.0.0",
22
+ "@graphql-inspector/graphql-loader": "^6.0.0",
23
+ "@graphql-inspector/introspect-command": "^6.0.0",
24
+ "@graphql-inspector/json-loader": "^6.0.0",
25
+ "@graphql-inspector/loaders": "^5.0.0",
26
+ "@graphql-inspector/serve-command": "^6.0.0",
27
+ "@graphql-inspector/similar-command": "^6.0.0",
28
+ "@graphql-inspector/url-loader": "^6.0.0",
29
+ "@graphql-inspector/validate-command": "^6.0.0"
30
30
  },
31
31
  "repository": {
32
32
  "type": "git",
@@ -524,7 +524,7 @@ type InputAddedMeta = TypeAddedMeta<Kind.INPUT_OBJECT_TYPE_DEFINITION> & {
524
524
  };
525
525
  export type TypeAddedChange = {
526
526
  type: typeof ChangeType.TypeAdded;
527
- meta: InputAddedMeta | TypeAddedMeta<Kind.ENUM_TYPE_DEFINITION | Kind.OBJECT_TYPE_DEFINITION | Kind.INTERFACE_TYPE_DEFINITION | Kind.UNION_TYPE_DEFINITION | Kind.SCALAR_TYPE_DEFINITION>;
527
+ meta: InputAddedMeta | TypeAddedMeta<typeof Kind.ENUM_TYPE_DEFINITION | typeof Kind.OBJECT_TYPE_DEFINITION | typeof Kind.INTERFACE_TYPE_DEFINITION | typeof Kind.UNION_TYPE_DEFINITION | typeof Kind.SCALAR_TYPE_DEFINITION>;
528
528
  };
529
529
  export type TypeKindChangedChange = {
530
530
  type: typeof ChangeType.TypeKindChanged;
@@ -524,7 +524,7 @@ type InputAddedMeta = TypeAddedMeta<Kind.INPUT_OBJECT_TYPE_DEFINITION> & {
524
524
  };
525
525
  export type TypeAddedChange = {
526
526
  type: typeof ChangeType.TypeAdded;
527
- meta: InputAddedMeta | TypeAddedMeta<Kind.ENUM_TYPE_DEFINITION | Kind.OBJECT_TYPE_DEFINITION | Kind.INTERFACE_TYPE_DEFINITION | Kind.UNION_TYPE_DEFINITION | Kind.SCALAR_TYPE_DEFINITION>;
527
+ meta: InputAddedMeta | TypeAddedMeta<typeof Kind.ENUM_TYPE_DEFINITION | typeof Kind.OBJECT_TYPE_DEFINITION | typeof Kind.INTERFACE_TYPE_DEFINITION | typeof Kind.UNION_TYPE_DEFINITION | typeof Kind.SCALAR_TYPE_DEFINITION>;
528
528
  };
529
529
  export type TypeKindChangedChange = {
530
530
  type: typeof ChangeType.TypeKindChanged;
@@ -1,4 +1,4 @@
1
- import { DirectiveLocationEnum, GraphQLArgument, GraphQLDirective } from 'graphql';
1
+ import { DirectiveLocation, GraphQLArgument, GraphQLDirective } from 'graphql';
2
2
  import { Change, ChangeType, CriticalityLevel, DirectiveAddedChange, DirectiveArgumentAddedChange, DirectiveArgumentDefaultValueChangedChange, DirectiveArgumentDescriptionChangedChange, DirectiveArgumentRemovedChange, DirectiveArgumentTypeChangedChange, DirectiveDescriptionChangedChange, DirectiveLocationAddedChange, DirectiveLocationRemovedChange, DirectiveRemovedChange, DirectiveRepeatableAddedChange, DirectiveRepeatableRemovedChange } from './change.cjs';
3
3
  export declare function directiveRemovedFromMeta(args: DirectiveRemovedChange): {
4
4
  readonly criticality: {
@@ -58,7 +58,7 @@ export declare function directiveLocationAddedFromMeta(args: DirectiveLocationAd
58
58
  addedDirectiveLocation: string;
59
59
  };
60
60
  };
61
- export declare function directiveLocationAdded(directive: GraphQLDirective, location: DirectiveLocationEnum): Change<typeof ChangeType.DirectiveLocationAdded>;
61
+ export declare function directiveLocationAdded(directive: GraphQLDirective, location: DirectiveLocation): Change<typeof ChangeType.DirectiveLocationAdded>;
62
62
  export declare function directiveLocationRemovedFromMeta(args: DirectiveLocationRemovedChange): {
63
63
  readonly criticality: {
64
64
  readonly level: CriticalityLevel.Breaking;
@@ -72,7 +72,7 @@ export declare function directiveLocationRemovedFromMeta(args: DirectiveLocation
72
72
  removedDirectiveLocation: string;
73
73
  };
74
74
  };
75
- export declare function directiveLocationRemoved(directive: GraphQLDirective, location: DirectiveLocationEnum): Change<typeof ChangeType.DirectiveLocationRemoved>;
75
+ export declare function directiveLocationRemoved(directive: GraphQLDirective, location: DirectiveLocation): Change<typeof ChangeType.DirectiveLocationRemoved>;
76
76
  export declare function directiveArgumentAddedFromMeta(args: DirectiveArgumentAddedChange): {
77
77
  readonly criticality: {
78
78
  level: CriticalityLevel;
@@ -1,4 +1,4 @@
1
- import { DirectiveLocationEnum, GraphQLArgument, GraphQLDirective } from 'graphql';
1
+ import { DirectiveLocation, GraphQLArgument, GraphQLDirective } from 'graphql';
2
2
  import { Change, ChangeType, CriticalityLevel, DirectiveAddedChange, DirectiveArgumentAddedChange, DirectiveArgumentDefaultValueChangedChange, DirectiveArgumentDescriptionChangedChange, DirectiveArgumentRemovedChange, DirectiveArgumentTypeChangedChange, DirectiveDescriptionChangedChange, DirectiveLocationAddedChange, DirectiveLocationRemovedChange, DirectiveRemovedChange, DirectiveRepeatableAddedChange, DirectiveRepeatableRemovedChange } from './change.js';
3
3
  export declare function directiveRemovedFromMeta(args: DirectiveRemovedChange): {
4
4
  readonly criticality: {
@@ -58,7 +58,7 @@ export declare function directiveLocationAddedFromMeta(args: DirectiveLocationAd
58
58
  addedDirectiveLocation: string;
59
59
  };
60
60
  };
61
- export declare function directiveLocationAdded(directive: GraphQLDirective, location: DirectiveLocationEnum): Change<typeof ChangeType.DirectiveLocationAdded>;
61
+ export declare function directiveLocationAdded(directive: GraphQLDirective, location: DirectiveLocation): Change<typeof ChangeType.DirectiveLocationAdded>;
62
62
  export declare function directiveLocationRemovedFromMeta(args: DirectiveLocationRemovedChange): {
63
63
  readonly criticality: {
64
64
  readonly level: CriticalityLevel.Breaking;
@@ -72,7 +72,7 @@ export declare function directiveLocationRemovedFromMeta(args: DirectiveLocation
72
72
  removedDirectiveLocation: string;
73
73
  };
74
74
  };
75
- export declare function directiveLocationRemoved(directive: GraphQLDirective, location: DirectiveLocationEnum): Change<typeof ChangeType.DirectiveLocationRemoved>;
75
+ export declare function directiveLocationRemoved(directive: GraphQLDirective, location: DirectiveLocation): Change<typeof ChangeType.DirectiveLocationRemoved>;
76
76
  export declare function directiveArgumentAddedFromMeta(args: DirectiveArgumentAddedChange): {
77
77
  readonly criticality: {
78
78
  level: CriticalityLevel;
@@ -1,4 +1,4 @@
1
- import { Kind, type GraphQLNamedType } from 'graphql';
1
+ import { type GraphQLNamedType } from 'graphql';
2
2
  import { Change, ChangeType, CriticalityLevel, TypeAddedChange, TypeDescriptionAddedChange, TypeDescriptionChangedChange, TypeDescriptionRemovedChange, TypeKindChangedChange, TypeRemovedChange } from './change.cjs';
3
3
  export declare function typeRemovedFromMeta(args: TypeRemovedChange): {
4
4
  readonly criticality: {
@@ -20,12 +20,12 @@ export declare function typeAddedFromMeta(args: TypeAddedChange): {
20
20
  readonly message: string;
21
21
  readonly meta: ({
22
22
  addedTypeName: string;
23
- addedTypeKind: Kind.INPUT_OBJECT_TYPE_DEFINITION;
23
+ addedTypeKind: "InputObjectTypeDefinition";
24
24
  } & {
25
25
  addedTypeIsOneOf: boolean;
26
26
  }) | {
27
27
  addedTypeName: string;
28
- addedTypeKind: Kind.SCALAR_TYPE_DEFINITION | Kind.OBJECT_TYPE_DEFINITION | Kind.INTERFACE_TYPE_DEFINITION | Kind.UNION_TYPE_DEFINITION | Kind.ENUM_TYPE_DEFINITION;
28
+ addedTypeKind: "ScalarTypeDefinition" | "ObjectTypeDefinition" | "InterfaceTypeDefinition" | "UnionTypeDefinition" | "EnumTypeDefinition";
29
29
  };
30
30
  readonly path: string;
31
31
  };
@@ -1,4 +1,4 @@
1
- import { Kind, type GraphQLNamedType } from 'graphql';
1
+ import { type GraphQLNamedType } from 'graphql';
2
2
  import { Change, ChangeType, CriticalityLevel, TypeAddedChange, TypeDescriptionAddedChange, TypeDescriptionChangedChange, TypeDescriptionRemovedChange, TypeKindChangedChange, TypeRemovedChange } from './change.js';
3
3
  export declare function typeRemovedFromMeta(args: TypeRemovedChange): {
4
4
  readonly criticality: {
@@ -20,12 +20,12 @@ export declare function typeAddedFromMeta(args: TypeAddedChange): {
20
20
  readonly message: string;
21
21
  readonly meta: ({
22
22
  addedTypeName: string;
23
- addedTypeKind: Kind.INPUT_OBJECT_TYPE_DEFINITION;
23
+ addedTypeKind: "InputObjectTypeDefinition";
24
24
  } & {
25
25
  addedTypeIsOneOf: boolean;
26
26
  }) | {
27
27
  addedTypeName: string;
28
- addedTypeKind: Kind.SCALAR_TYPE_DEFINITION | Kind.OBJECT_TYPE_DEFINITION | Kind.INTERFACE_TYPE_DEFINITION | Kind.UNION_TYPE_DEFINITION | Kind.ENUM_TYPE_DEFINITION;
28
+ addedTypeKind: "ScalarTypeDefinition" | "ObjectTypeDefinition" | "InterfaceTypeDefinition" | "UnionTypeDefinition" | "EnumTypeDefinition";
29
29
  };
30
30
  readonly path: string;
31
31
  };
@@ -1,7 +1,19 @@
1
- import { DocumentNode, FieldNode, GraphQLError, GraphQLInputType, GraphQLNamedType, GraphQLOutputType, GraphQLSchema, KindEnum } from 'graphql';
1
+ import { ConstValueNode, DocumentNode, FieldNode, GraphQLArgument, GraphQLError, GraphQLInputField, GraphQLInputType, GraphQLNamedType, GraphQLOutputType, GraphQLSchema, Kind } from 'graphql';
2
+ type GraphQLInputValue = (GraphQLArgument | GraphQLInputField) & {
3
+ default?: {
4
+ literal: ConstValueNode;
5
+ value?: never;
6
+ } | {
7
+ value: unknown;
8
+ literal?: never;
9
+ };
10
+ };
11
+ export declare function getDefaultValue(inputValue: GraphQLInputValue): unknown;
12
+ export declare function hasDefaultValue(inputValue: GraphQLInputValue): boolean;
13
+ export declare function defaultValuesAreEqual(oldInputValue: GraphQLInputValue | null | undefined, newInputValue: GraphQLInputValue): boolean;
2
14
  export declare function safeChangeForField(oldType: GraphQLOutputType, newType: GraphQLOutputType): boolean;
3
15
  export declare function safeChangeForInputValue(oldType: GraphQLInputType, newType: GraphQLInputType): boolean;
4
- export declare function getKind(type: GraphQLNamedType): KindEnum;
16
+ export declare function getKind(type: GraphQLNamedType): Kind;
5
17
  export declare function getTypePrefix(type: GraphQLNamedType): string;
6
18
  export declare function isPrimitive(type: GraphQLNamedType | string): boolean;
7
19
  export declare function isForIntrospection(type: GraphQLNamedType | string): boolean;
@@ -9,3 +21,4 @@ export declare function findDeprecatedUsages(schema: GraphQLSchema, ast: Documen
9
21
  export declare function removeFieldIfDirectives(node: FieldNode, directiveNames: string[]): FieldNode | null;
10
22
  export declare function removeDirectives(node: FieldNode, directiveNames: string[]): FieldNode;
11
23
  export declare function getReachableTypes(schema: GraphQLSchema): Set<string>;
24
+ export {};
@@ -1,7 +1,19 @@
1
- import { DocumentNode, FieldNode, GraphQLError, GraphQLInputType, GraphQLNamedType, GraphQLOutputType, GraphQLSchema, KindEnum } from 'graphql';
1
+ import { ConstValueNode, DocumentNode, FieldNode, GraphQLArgument, GraphQLError, GraphQLInputField, GraphQLInputType, GraphQLNamedType, GraphQLOutputType, GraphQLSchema, Kind } from 'graphql';
2
+ type GraphQLInputValue = (GraphQLArgument | GraphQLInputField) & {
3
+ default?: {
4
+ literal: ConstValueNode;
5
+ value?: never;
6
+ } | {
7
+ value: unknown;
8
+ literal?: never;
9
+ };
10
+ };
11
+ export declare function getDefaultValue(inputValue: GraphQLInputValue): unknown;
12
+ export declare function hasDefaultValue(inputValue: GraphQLInputValue): boolean;
13
+ export declare function defaultValuesAreEqual(oldInputValue: GraphQLInputValue | null | undefined, newInputValue: GraphQLInputValue): boolean;
2
14
  export declare function safeChangeForField(oldType: GraphQLOutputType, newType: GraphQLOutputType): boolean;
3
15
  export declare function safeChangeForInputValue(oldType: GraphQLInputType, newType: GraphQLInputType): boolean;
4
- export declare function getKind(type: GraphQLNamedType): KindEnum;
16
+ export declare function getKind(type: GraphQLNamedType): Kind;
5
17
  export declare function getTypePrefix(type: GraphQLNamedType): string;
6
18
  export declare function isPrimitive(type: GraphQLNamedType | string): boolean;
7
19
  export declare function isForIntrospection(type: GraphQLNamedType | string): boolean;
@@ -9,3 +21,4 @@ export declare function findDeprecatedUsages(schema: GraphQLSchema, ast: Documen
9
21
  export declare function removeFieldIfDirectives(node: FieldNode, directiveNames: string[]): FieldNode | null;
10
22
  export declare function removeDirectives(node: FieldNode, directiveNames: string[]): FieldNode;
11
23
  export declare function getReachableTypes(schema: GraphQLSchema): Set<string>;
24
+ export {};