@graphql-eslint/eslint-plugin 4.0.0-alpha.0 → 4.0.0-alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +0 -2
- package/{esm/cache.d.mts → cjs/cache.d.cts} +1 -1
- package/cjs/cache.js +1 -1
- package/cjs/configs/index.d.cts +9 -0
- package/cjs/configs/index.js +1 -1
- package/cjs/documents.js +1 -1
- package/{esm/estree-converter/converter.d.mts → cjs/estree-converter/converter.d.cts} +1 -1
- package/cjs/estree-converter/index.d.cts +8 -0
- package/{esm/estree-converter/types.d.mts → cjs/estree-converter/types.d.cts} +1 -1
- package/{esm/estree-converter/utils.d.mts → cjs/estree-converter/utils.d.cts} +3 -3
- package/cjs/flat-configs.d.cts +75 -0
- package/cjs/flat-configs.js +1 -3
- package/{esm/graphql-config.d.mts → cjs/graphql-config.d.cts} +3 -3
- package/cjs/graphql-config.js +2 -2
- package/{esm/index.d.mts → cjs/index.d.cts} +15 -12
- package/cjs/index.js +2 -0
- package/cjs/meta.d.cts +4 -0
- package/cjs/meta.js +36 -0
- package/cjs/package.json +1 -0
- package/{esm/parser.d.mts → cjs/parser.d.cts} +12 -5
- package/cjs/parser.js +13 -4
- package/{esm/processor.d.mts → cjs/processor.d.cts} +5 -1
- package/cjs/processor.js +5 -1
- package/{esm/rules/alphabetize.d.mts → cjs/rules/alphabetize.d.cts} +5 -5
- package/cjs/rules/alphabetize.js +1 -1
- package/{esm/rules/description-style.d.mts → cjs/rules/description-style.d.cts} +5 -5
- package/{esm/rules/graphql-js-validation.d.mts → cjs/rules/graphql-js-validation.d.cts} +4 -4
- package/{esm/rules/index.d.mts → cjs/rules/index.d.cts} +8 -9
- package/cjs/rules/index.js +1 -1
- package/{esm/rules/input-name.d.mts → cjs/rules/input-name.d.cts} +5 -5
- package/{esm/rules/lone-executable-definition.d.mts → cjs/rules/lone-executable-definition.d.cts} +5 -5
- package/{esm/rules/match-document-filename.d.mts → cjs/rules/match-document-filename.d.cts} +6 -6
- package/cjs/rules/match-document-filename.js +2 -2
- package/{esm/rules/naming-convention.d.mts → cjs/rules/naming-convention.d.cts} +5 -5
- package/cjs/rules/no-anonymous-operations.d.cts +13 -0
- package/{esm/rules/no-deprecated.d.mts → cjs/rules/no-deprecated.d.cts} +4 -4
- package/cjs/rules/no-duplicate-fields.d.cts +13 -0
- package/{esm/rules/no-hashtag-description.d.mts → cjs/rules/no-hashtag-description.d.cts} +4 -4
- package/cjs/rules/no-one-place-fragments.d.cts +13 -0
- package/{esm/rules/no-root-type.d.mts → cjs/rules/no-root-type.d.cts} +5 -5
- package/cjs/rules/no-scalar-result-type-on-mutation.d.cts +13 -0
- package/cjs/rules/no-typename-prefix.d.cts +13 -0
- package/cjs/rules/no-unreachable-types.d.cts +13 -0
- package/cjs/rules/no-unreachable-types.js +7 -9
- package/cjs/rules/no-unused-fields.d.cts +13 -0
- package/cjs/rules/no-unused-fields.js +6 -6
- package/{esm/rules/relay-arguments.d.mts → cjs/rules/relay-arguments.d.cts} +5 -5
- package/{esm/rules/relay-connection-types.d.mts → cjs/rules/relay-connection-types.d.cts} +4 -4
- package/{esm/rules/relay-edge-types.d.mts → cjs/rules/relay-edge-types.d.cts} +5 -5
- package/cjs/rules/relay-edge-types.js +2 -2
- package/cjs/rules/relay-page-info.d.cts +13 -0
- package/cjs/rules/relay-page-info.js +1 -1
- package/{esm/rules/require-deprecation-date.d.mts → cjs/rules/require-deprecation-date.d.cts} +5 -5
- package/cjs/rules/require-deprecation-reason.d.cts +13 -0
- package/{esm/rules/require-description.d.mts → cjs/rules/require-description.d.cts} +5 -5
- package/cjs/rules/require-description.js +1 -1
- package/cjs/rules/require-field-of-type-query-in-mutation-result.d.cts +13 -0
- package/cjs/rules/require-import-fragment.d.cts +13 -0
- package/cjs/rules/require-import-fragment.js +5 -9
- package/cjs/rules/require-nullable-fields-with-oneof.d.cts +13 -0
- package/cjs/rules/require-nullable-result-in-root.d.cts +13 -0
- package/{esm/rules/require-selections.d.mts → cjs/rules/require-selections.d.cts} +5 -5
- package/cjs/rules/require-selections.js +2 -1
- package/cjs/rules/require-type-pattern-with-oneof.d.cts +13 -0
- package/{esm/rules/selection-set-depth.d.mts → cjs/rules/selection-set-depth.d.cts} +5 -5
- package/cjs/rules/selection-set-depth.js +2 -2
- package/{esm/rules/strict-id-in-types.d.mts → cjs/rules/strict-id-in-types.d.cts} +5 -5
- package/cjs/rules/unique-enum-value-names.d.cts +13 -0
- package/{esm/rules/unique-fragment-name.d.mts → cjs/rules/unique-fragment-name.d.cts} +4 -4
- package/cjs/rules/unique-operation-name.d.cts +13 -0
- package/{esm/schema.d.mts → cjs/schema.d.cts} +3 -3
- package/cjs/schema.js +1 -1
- package/{esm/siblings.d.mts → cjs/siblings.d.cts} +2 -2
- package/{esm/types.d.mts → cjs/types.d.cts} +5 -4
- package/{esm/utils.d.mts → cjs/utils.d.cts} +5 -5
- package/cjs/utils.js +1 -1
- package/{cjs → esm}/cache.d.ts +1 -1
- package/esm/cache.js +1 -1
- package/esm/configs/index.d.ts +9 -0
- package/esm/configs/index.js +1 -1
- package/esm/configs/operations-all.js +1 -1
- package/esm/configs/operations-recommended.js +1 -1
- package/esm/configs/schema-all.js +1 -1
- package/esm/configs/schema-recommended.js +1 -1
- package/esm/configs/schema-relay.js +1 -1
- package/esm/documents.js +1 -1
- package/esm/estree-converter/converter.js +1 -1
- package/{cjs → esm}/estree-converter/index.d.ts +2 -2
- package/{cjs → esm}/estree-converter/types.d.ts +1 -1
- package/{cjs → esm}/estree-converter/utils.d.ts +3 -3
- package/esm/estree-converter/utils.js +1 -1
- package/esm/flat-configs.d.ts +75 -0
- package/esm/flat-configs.js +3 -5
- package/esm/graphql-config.js +3 -3
- package/{cjs → esm}/index.d.ts +7 -4
- package/esm/index.js +3 -2
- package/esm/meta.d.ts +4 -0
- package/esm/meta.js +7 -0
- package/{cjs → esm}/parser.d.ts +10 -3
- package/esm/parser.js +13 -4
- package/{cjs → esm}/processor.d.ts +5 -1
- package/esm/processor.js +6 -1
- package/{cjs → esm}/rules/alphabetize.d.ts +3 -3
- package/esm/rules/alphabetize.js +1 -1
- package/{cjs → esm}/rules/description-style.d.ts +3 -3
- package/esm/rules/description-style.js +1 -1
- package/esm/rules/graphql-js-validation.js +1 -1
- package/{cjs → esm}/rules/index.d.ts +4 -5
- package/esm/rules/index.js +2 -2
- package/{cjs → esm}/rules/input-name.d.ts +3 -3
- package/esm/rules/input-name.js +1 -1
- package/{cjs → esm}/rules/lone-executable-definition.d.ts +3 -3
- package/esm/rules/lone-executable-definition.js +1 -1
- package/{cjs → esm}/rules/match-document-filename.d.ts +3 -3
- package/esm/rules/match-document-filename.js +3 -3
- package/{cjs → esm}/rules/naming-convention.d.ts +3 -3
- package/esm/rules/naming-convention.js +1 -1
- package/esm/rules/no-anonymous-operations.js +1 -1
- package/esm/rules/no-deprecated.js +1 -1
- package/esm/rules/no-duplicate-fields.js +1 -1
- package/esm/rules/no-hashtag-description.js +1 -1
- package/esm/rules/no-one-place-fragments.js +1 -1
- package/{cjs → esm}/rules/no-root-type.d.ts +3 -3
- package/esm/rules/no-root-type.js +1 -1
- package/esm/rules/no-scalar-result-type-on-mutation.js +1 -1
- package/esm/rules/no-typename-prefix.js +1 -1
- package/esm/rules/no-unreachable-types.js +8 -9
- package/esm/rules/no-unused-fields.js +7 -6
- package/{cjs → esm}/rules/relay-arguments.d.ts +3 -3
- package/esm/rules/relay-arguments.js +1 -1
- package/esm/rules/relay-connection-types.js +1 -1
- package/{cjs → esm}/rules/relay-edge-types.d.ts +3 -3
- package/esm/rules/relay-edge-types.js +3 -3
- package/esm/rules/relay-page-info.js +2 -2
- package/{cjs → esm}/rules/require-deprecation-date.d.ts +3 -3
- package/esm/rules/require-deprecation-date.js +1 -1
- package/esm/rules/require-deprecation-reason.js +1 -1
- package/{cjs → esm}/rules/require-description.d.ts +3 -3
- package/esm/rules/require-description.js +2 -2
- package/esm/rules/require-field-of-type-query-in-mutation-result.js +1 -1
- package/esm/rules/require-import-fragment.js +5 -9
- package/esm/rules/require-nullable-fields-with-oneof.js +1 -1
- package/esm/rules/require-nullable-result-in-root.js +1 -1
- package/{cjs → esm}/rules/require-selections.d.ts +3 -3
- package/esm/rules/require-selections.js +3 -2
- package/esm/rules/require-type-pattern-with-oneof.js +1 -1
- package/{cjs → esm}/rules/selection-set-depth.d.ts +3 -3
- package/esm/rules/selection-set-depth.js +2 -2
- package/{cjs → esm}/rules/strict-id-in-types.d.ts +3 -3
- package/esm/rules/strict-id-in-types.js +1 -1
- package/esm/rules/unique-enum-value-names.js +1 -1
- package/esm/rules/unique-fragment-name.js +1 -1
- package/esm/rules/unique-operation-name.js +1 -1
- package/esm/schema.js +1 -1
- package/{cjs → esm}/siblings.d.ts +2 -2
- package/esm/siblings.js +1 -1
- package/{cjs → esm}/types.d.ts +4 -3
- package/{cjs → esm}/utils.d.ts +3 -3
- package/esm/utils.js +1 -1
- package/{index.browser.mjs → index.browser.js} +885 -785
- package/package.json +9 -8
- package/cjs/configs/index.d.ts +0 -174
- package/cjs/flat-configs.d.ts +0 -307
- package/esm/configs/index.d.mts +0 -174
- package/esm/estree-converter/index.d.mts +0 -8
- package/esm/flat-configs.d.mts +0 -307
- package/esm/package.json +0 -1
- package/esm/rules/no-anonymous-operations.d.mts +0 -13
- package/esm/rules/no-duplicate-fields.d.mts +0 -13
- package/esm/rules/no-one-place-fragments.d.mts +0 -13
- package/esm/rules/no-scalar-result-type-on-mutation.d.mts +0 -13
- package/esm/rules/no-typename-prefix.d.mts +0 -13
- package/esm/rules/no-unreachable-types.d.mts +0 -13
- package/esm/rules/no-unused-fields.d.mts +0 -13
- package/esm/rules/relay-page-info.d.mts +0 -13
- package/esm/rules/require-deprecation-reason.d.mts +0 -13
- package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +0 -13
- package/esm/rules/require-import-fragment.d.mts +0 -13
- package/esm/rules/require-nullable-fields-with-oneof.d.mts +0 -13
- package/esm/rules/require-nullable-result-in-root.d.mts +0 -13
- package/esm/rules/require-type-pattern-with-oneof.d.mts +0 -13
- package/esm/rules/unique-enum-value-names.d.mts +0 -13
- package/esm/rules/unique-operation-name.d.mts +0 -13
- package/cjs/configs/{operations-all.d.ts → operations-all.d.cts} +0 -0
- package/cjs/configs/{operations-recommended.d.ts → operations-recommended.d.cts} +0 -0
- package/cjs/configs/{schema-all.d.ts → schema-all.d.cts} +0 -0
- package/cjs/configs/{schema-recommended.d.ts → schema-recommended.d.cts} +0 -0
- package/cjs/configs/{schema-relay.d.ts → schema-relay.d.cts} +0 -0
- package/{esm/documents.d.mts → cjs/documents.d.cts} +1 -1
- package/esm/{chunk-U3TKCM4X.js → chunk-UIAXBAMD.js} +0 -0
- package/esm/configs/{operations-all.d.mts → operations-all.d.ts} +0 -0
- package/esm/configs/{operations-recommended.d.mts → operations-recommended.d.ts} +0 -0
- package/esm/configs/{schema-all.d.mts → schema-all.d.ts} +0 -0
- package/esm/configs/{schema-recommended.d.mts → schema-recommended.d.ts} +0 -0
- package/esm/configs/{schema-relay.d.mts → schema-relay.d.ts} +0 -0
- package/{cjs → esm}/documents.d.ts +1 -1
- package/{cjs → esm}/estree-converter/converter.d.ts +0 -0
- package/{cjs → esm}/graphql-config.d.ts +1 -1
- package/{cjs → esm}/rules/graphql-js-validation.d.ts +2 -2
- package/{cjs → esm}/rules/no-anonymous-operations.d.ts +2 -2
- package/{cjs → esm}/rules/no-deprecated.d.ts +2 -2
- package/{cjs → esm}/rules/no-duplicate-fields.d.ts +2 -2
- package/{cjs → esm}/rules/no-hashtag-description.d.ts +2 -2
- package/{cjs → esm}/rules/no-one-place-fragments.d.ts +2 -2
- package/{cjs → esm}/rules/no-scalar-result-type-on-mutation.d.ts +2 -2
- package/{cjs → esm}/rules/no-typename-prefix.d.ts +2 -2
- package/{cjs → esm}/rules/no-unreachable-types.d.ts +2 -2
- package/{cjs → esm}/rules/no-unused-fields.d.ts +2 -2
- package/{cjs → esm}/rules/relay-connection-types.d.ts +2 -2
- package/{cjs → esm}/rules/relay-page-info.d.ts +2 -2
- package/{cjs → esm}/rules/require-deprecation-reason.d.ts +2 -2
- package/{cjs → esm}/rules/require-field-of-type-query-in-mutation-result.d.ts +2 -2
- package/{cjs → esm}/rules/require-import-fragment.d.ts +2 -2
- package/{cjs → esm}/rules/require-nullable-fields-with-oneof.d.ts +2 -2
- package/{cjs → esm}/rules/require-nullable-result-in-root.d.ts +2 -2
- package/{cjs → esm}/rules/require-type-pattern-with-oneof.d.ts +2 -2
- package/{cjs → esm}/rules/unique-enum-value-names.d.ts +2 -2
- package/{cjs → esm}/rules/unique-fragment-name.d.ts +1 -1
- package/{cjs → esm}/rules/unique-operation-name.d.ts +2 -2
- package/{cjs → esm}/schema.d.ts +1 -1
@@ -237,9 +237,31 @@ var require_schema_relay = __commonJS({
|
|
237
237
|
});
|
238
238
|
|
239
239
|
// src/parser.ts
|
240
|
+
import debugFactory2 from "debug";
|
241
|
+
import { buildSchema, GraphQLError } from "graphql";
|
240
242
|
import { parseGraphQLSDL } from "@graphql-tools/utils";
|
243
|
+
|
244
|
+
// src/cache.ts
|
241
245
|
import debugFactory from "debug";
|
242
|
-
|
246
|
+
var log = debugFactory("graphql-eslint:ModuleCache"), ModuleCache = class {
|
247
|
+
map = /* @__PURE__ */ new Map();
|
248
|
+
set(cacheKey, result) {
|
249
|
+
this.map.set(cacheKey, { lastSeen: process.hrtime(), result }), log("setting entry for", cacheKey);
|
250
|
+
}
|
251
|
+
get(cacheKey, settings = {
|
252
|
+
lifetime: 10
|
253
|
+
/* seconds */
|
254
|
+
}) {
|
255
|
+
let value = this.map.get(cacheKey);
|
256
|
+
if (!value) {
|
257
|
+
log("cache miss for", cacheKey);
|
258
|
+
return;
|
259
|
+
}
|
260
|
+
let { lastSeen, result } = value;
|
261
|
+
if (process.env.NODE || process.hrtime(lastSeen)[0] < settings.lifetime)
|
262
|
+
return result;
|
263
|
+
}
|
264
|
+
};
|
243
265
|
|
244
266
|
// src/estree-converter/converter.ts
|
245
267
|
import {
|
@@ -374,6 +396,84 @@ function convertToESTree(node, schema15) {
|
|
374
396
|
);
|
375
397
|
}
|
376
398
|
|
399
|
+
// package.json
|
400
|
+
var package_default = {
|
401
|
+
name: "@graphql-eslint/eslint-plugin",
|
402
|
+
version: "4.0.0-alpha.2",
|
403
|
+
type: "module",
|
404
|
+
description: "GraphQL plugin for ESLint",
|
405
|
+
repository: "https://github.com/B2o5T/graphql-eslint",
|
406
|
+
author: "Dotan Simha <dotansimha@gmail.com>",
|
407
|
+
license: "MIT",
|
408
|
+
engines: {
|
409
|
+
node: ">=18"
|
410
|
+
},
|
411
|
+
main: "dist/cjs/index.js",
|
412
|
+
exports: {
|
413
|
+
"./package.json": "./package.json",
|
414
|
+
".": {
|
415
|
+
require: {
|
416
|
+
types: "./dist/cjs/index.d.ts",
|
417
|
+
default: "./dist/cjs/index.js"
|
418
|
+
},
|
419
|
+
import: {
|
420
|
+
types: "./dist/esm/index.d.ts",
|
421
|
+
default: "./dist/esm/index.js"
|
422
|
+
},
|
423
|
+
default: {
|
424
|
+
types: "./dist/esm/index.d.ts",
|
425
|
+
default: "./dist/esm/index.js"
|
426
|
+
}
|
427
|
+
}
|
428
|
+
},
|
429
|
+
types: "dist/esm/index.d.ts",
|
430
|
+
keywords: [
|
431
|
+
"eslint",
|
432
|
+
"eslintplugin",
|
433
|
+
"eslint-plugin",
|
434
|
+
"graphql"
|
435
|
+
],
|
436
|
+
scripts: {
|
437
|
+
build: "tsup",
|
438
|
+
test: "vitest",
|
439
|
+
typecheck: "tsc --noEmit"
|
440
|
+
},
|
441
|
+
peerDependencies: {
|
442
|
+
eslint: ">=8.44.0",
|
443
|
+
graphql: "^16"
|
444
|
+
},
|
445
|
+
dependencies: {
|
446
|
+
"@graphql-tools/code-file-loader": "^8.0.0",
|
447
|
+
"@graphql-tools/graphql-tag-pluck": "^8.0.0",
|
448
|
+
"@graphql-tools/utils": "^10.0.0",
|
449
|
+
debug: "^4.3.4",
|
450
|
+
"fast-glob": "^3.2.12",
|
451
|
+
"graphql-config": "^5.0.0",
|
452
|
+
"graphql-depth-limit": "^1.1.0",
|
453
|
+
"lodash.lowercase": "^4.3.0"
|
454
|
+
},
|
455
|
+
devDependencies: {
|
456
|
+
"@theguild/eslint-rule-tester": "workspace:*",
|
457
|
+
"@types/debug": "4.1.12",
|
458
|
+
"@types/eslint": "9.6.0",
|
459
|
+
"@types/estree": "1.0.5",
|
460
|
+
"@types/graphql-depth-limit": "1.1.6",
|
461
|
+
"@types/json-schema": "7.0.15",
|
462
|
+
"@types/lodash.lowercase": "4.3.9",
|
463
|
+
graphql: "16.9.0",
|
464
|
+
"json-schema-to-ts": "2.12.0",
|
465
|
+
"vite-tsconfig-paths": "^4.3.2"
|
466
|
+
},
|
467
|
+
publishConfig: {
|
468
|
+
directory: "dist",
|
469
|
+
access: "public"
|
470
|
+
},
|
471
|
+
sideEffects: !1
|
472
|
+
};
|
473
|
+
|
474
|
+
// src/meta.ts
|
475
|
+
var { name, version } = package_default;
|
476
|
+
|
377
477
|
// src/siblings.ts
|
378
478
|
import {
|
379
479
|
Kind as Kind3,
|
@@ -550,7 +650,7 @@ function getSiblings(documents) {
|
|
550
650
|
cachedOperations = result;
|
551
651
|
}
|
552
652
|
return cachedOperations;
|
553
|
-
}, getFragment = (
|
653
|
+
}, getFragment = (name2) => getFragments().filter((f) => f.document.name.value === name2), collectFragments = (selectable, recursive, collected = /* @__PURE__ */ new Map()) => (visit2(selectable, {
|
554
654
|
FragmentSpread(spread) {
|
555
655
|
let fragmentName = spread.name.value, [fragment] = getFragment(fragmentName);
|
556
656
|
if (!fragment) {
|
@@ -567,7 +667,7 @@ function getSiblings(documents) {
|
|
567
667
|
getFragments,
|
568
668
|
getFragmentByType: (typeName) => getFragments().filter((f) => f.document.typeCondition.name.value === typeName),
|
569
669
|
getFragmentsInUse: (selectable, recursive = !0) => Array.from(collectFragments(selectable, recursive).values()),
|
570
|
-
getOperation: (
|
670
|
+
getOperation: (name2) => getOperations().filter((o) => o.document.name?.value === name2),
|
571
671
|
getOperations,
|
572
672
|
getOperationByType: (type) => getOperations().filter((o) => o.document.operation === type)
|
573
673
|
};
|
@@ -575,7 +675,7 @@ function getSiblings(documents) {
|
|
575
675
|
}
|
576
676
|
|
577
677
|
// src/parser.ts
|
578
|
-
var debug =
|
678
|
+
var debug = debugFactory2("graphql-eslint:parser");
|
579
679
|
debug("cwd %o", CWD);
|
580
680
|
var LEGACY_PARSER_OPTIONS_KEYS = [
|
581
681
|
"schema",
|
@@ -640,222 +740,603 @@ function parseForESLint(code, options) {
|
|
640
740
|
throw error;
|
641
741
|
}
|
642
742
|
}
|
743
|
+
var parser = {
|
744
|
+
parseForESLint,
|
745
|
+
meta: {
|
746
|
+
name: "@graphql-eslint/parser",
|
747
|
+
version
|
748
|
+
}
|
749
|
+
};
|
643
750
|
|
644
|
-
// src/rules/
|
751
|
+
// src/rules/alphabetize.ts
|
645
752
|
import {
|
646
|
-
Kind as Kind4
|
647
|
-
validate,
|
648
|
-
visit as visit3
|
753
|
+
Kind as Kind4
|
649
754
|
} from "graphql";
|
650
|
-
import
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
ValuesOfCorrectTypeRule,
|
679
|
-
VariablesAreInputTypesRule,
|
680
|
-
VariablesInAllowedPositionRule
|
681
|
-
} from "graphql/validation/index.js";
|
682
|
-
import { validateSDL } from "graphql/validation/validate.js";
|
683
|
-
function validateDocument({
|
684
|
-
context,
|
685
|
-
schema: schema15 = null,
|
686
|
-
documentNode,
|
687
|
-
rule: rule35,
|
688
|
-
hasDidYouMeanSuggestions
|
689
|
-
}) {
|
690
|
-
if (documentNode.definitions.length !== 0)
|
691
|
-
try {
|
692
|
-
let validationErrors = schema15 ? validate(schema15, documentNode, [rule35]) : validateSDL(documentNode, null, [rule35]);
|
693
|
-
for (let error of validationErrors) {
|
694
|
-
let { line, column } = error.locations[0], sourceCode = context.getSourceCode(), { tokens } = sourceCode.ast, token = tokens.find(
|
695
|
-
(token2) => token2.loc.start.line === line && token2.loc.start.column === column - 1
|
696
|
-
), loc = {
|
697
|
-
line,
|
698
|
-
column: column - 1
|
699
|
-
};
|
700
|
-
token && (loc = // if cursor on `@` symbol than use next node
|
701
|
-
token.type === "@" ? sourceCode.getNodeByRangeIndex(token.range[1] + 1).loc : token.loc);
|
702
|
-
let didYouMeanContent = error.message.match(/Did you mean (?<content>.*)\?$/)?.groups.content, matches = didYouMeanContent ? [...didYouMeanContent.matchAll(/"(?<name>[^"]*)"/g)] : [];
|
703
|
-
context.report({
|
704
|
-
loc,
|
705
|
-
message: error.message,
|
706
|
-
suggest: hasDidYouMeanSuggestions ? matches.map((match) => {
|
707
|
-
let { name } = match.groups;
|
708
|
-
return {
|
709
|
-
desc: `Rename to \`${name}\``,
|
710
|
-
fix: (fixer) => fixer.replaceText(token, name)
|
711
|
-
};
|
712
|
-
}) : []
|
713
|
-
});
|
714
|
-
}
|
715
|
-
} catch (error) {
|
716
|
-
context.report({
|
717
|
-
loc: REPORT_ON_FIRST_CHARACTER,
|
718
|
-
message: error.message
|
719
|
-
});
|
720
|
-
}
|
721
|
-
}
|
722
|
-
var getFragmentDefsAndFragmentSpreads = (node) => {
|
723
|
-
let fragmentDefs = /* @__PURE__ */ new Set(), fragmentSpreads = /* @__PURE__ */ new Set();
|
724
|
-
return visit3(node, {
|
725
|
-
FragmentDefinition(node2) {
|
726
|
-
fragmentDefs.add(node2.name.value);
|
727
|
-
},
|
728
|
-
FragmentSpread(node2) {
|
729
|
-
fragmentSpreads.add(node2.name.value);
|
730
|
-
}
|
731
|
-
}), { fragmentDefs, fragmentSpreads };
|
732
|
-
}, getMissingFragments = (node) => {
|
733
|
-
let { fragmentDefs, fragmentSpreads } = getFragmentDefsAndFragmentSpreads(node);
|
734
|
-
return [...fragmentSpreads].filter((name) => !fragmentDefs.has(name));
|
735
|
-
}, handleMissingFragments = ({ ruleId, context, node }) => {
|
736
|
-
let missingFragments = getMissingFragments(node);
|
737
|
-
if (missingFragments.length > 0) {
|
738
|
-
let siblings = requireSiblingsOperations(ruleId, context), fragmentsToAdd = [];
|
739
|
-
for (let fragmentName of missingFragments) {
|
740
|
-
let [foundFragment] = siblings.getFragment(fragmentName).map((source) => source.document);
|
741
|
-
foundFragment && fragmentsToAdd.push(foundFragment);
|
742
|
-
}
|
743
|
-
if (fragmentsToAdd.length > 0)
|
744
|
-
return handleMissingFragments({
|
745
|
-
ruleId,
|
746
|
-
context,
|
747
|
-
node: {
|
748
|
-
kind: Kind4.DOCUMENT,
|
749
|
-
definitions: [...node.definitions, ...fragmentsToAdd]
|
750
|
-
}
|
751
|
-
});
|
752
|
-
}
|
753
|
-
return node;
|
754
|
-
}, validationToRule = ({
|
755
|
-
ruleId,
|
756
|
-
rule: rule35,
|
757
|
-
getDocumentNode,
|
758
|
-
schema: schema15 = [],
|
759
|
-
hasDidYouMeanSuggestions
|
760
|
-
}, docs) => ({
|
761
|
-
[ruleId]: {
|
762
|
-
meta: {
|
763
|
-
docs: {
|
764
|
-
recommended: !0,
|
765
|
-
...docs,
|
766
|
-
graphQLJSRuleName: rule35.name,
|
767
|
-
url: `https://the-guild.dev/graphql/eslint/rules/${ruleId}`,
|
768
|
-
description: `${docs.description}
|
769
|
-
> This rule is a wrapper around a \`graphql-js\` validation function.`
|
755
|
+
import lowerCase2 from "lodash.lowercase";
|
756
|
+
var RULE_ID = "alphabetize", fieldsEnum = [
|
757
|
+
Kind4.OBJECT_TYPE_DEFINITION,
|
758
|
+
Kind4.INTERFACE_TYPE_DEFINITION,
|
759
|
+
Kind4.INPUT_OBJECT_TYPE_DEFINITION
|
760
|
+
], selectionsEnum = [
|
761
|
+
Kind4.OPERATION_DEFINITION,
|
762
|
+
Kind4.FRAGMENT_DEFINITION
|
763
|
+
], argumentsEnum = [
|
764
|
+
Kind4.FIELD_DEFINITION,
|
765
|
+
Kind4.FIELD,
|
766
|
+
Kind4.DIRECTIVE_DEFINITION,
|
767
|
+
Kind4.DIRECTIVE
|
768
|
+
], schema = {
|
769
|
+
type: "array",
|
770
|
+
minItems: 1,
|
771
|
+
maxItems: 1,
|
772
|
+
items: {
|
773
|
+
type: "object",
|
774
|
+
additionalProperties: !1,
|
775
|
+
minProperties: 1,
|
776
|
+
properties: {
|
777
|
+
fields: {
|
778
|
+
...ARRAY_DEFAULT_OPTIONS,
|
779
|
+
items: {
|
780
|
+
enum: fieldsEnum
|
781
|
+
},
|
782
|
+
description: "Fields of `type`, `interface`, and `input`."
|
770
783
|
},
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
create(context) {
|
775
|
-
return {
|
776
|
-
Document(node) {
|
777
|
-
let schema16 = docs.requiresSchema ? requireGraphQLSchemaFromContext(ruleId, context) : null, documentNode = getDocumentNode ? getDocumentNode({ ruleId, context, node: node.rawNode() }) : node.rawNode();
|
778
|
-
validateDocument({
|
779
|
-
context,
|
780
|
-
schema: schema16,
|
781
|
-
documentNode,
|
782
|
-
rule: rule35,
|
783
|
-
hasDidYouMeanSuggestions
|
784
|
-
});
|
785
|
-
}
|
786
|
-
};
|
787
|
-
}
|
788
|
-
}
|
789
|
-
}), GRAPHQL_JS_VALIDATIONS = Object.assign(
|
790
|
-
{},
|
791
|
-
validationToRule(
|
792
|
-
{
|
793
|
-
ruleId: "executable-definitions",
|
794
|
-
rule: ExecutableDefinitionsRule
|
795
|
-
},
|
796
|
-
{
|
797
|
-
category: "Operations",
|
798
|
-
description: "A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.",
|
799
|
-
requiresSchema: !0
|
800
|
-
}
|
801
|
-
),
|
802
|
-
validationToRule(
|
803
|
-
{
|
804
|
-
ruleId: "fields-on-correct-type",
|
805
|
-
rule: FieldsOnCorrectTypeRule,
|
806
|
-
hasDidYouMeanSuggestions: !0
|
807
|
-
},
|
808
|
-
{
|
809
|
-
category: "Operations",
|
810
|
-
description: "A GraphQL document is only valid if all fields selected are defined by the parent type, or are an allowed meta field such as `__typename`.",
|
811
|
-
requiresSchema: !0
|
812
|
-
}
|
813
|
-
),
|
814
|
-
validationToRule(
|
815
|
-
{
|
816
|
-
ruleId: "fragments-on-composite-type",
|
817
|
-
rule: FragmentsOnCompositeTypesRule
|
818
|
-
},
|
819
|
-
{
|
820
|
-
category: "Operations",
|
821
|
-
description: "Fragments use a type condition to determine if they apply, since fragments can only be spread into a composite type (object, interface, or union), the type condition must also be a composite type.",
|
822
|
-
requiresSchema: !0
|
823
|
-
}
|
824
|
-
),
|
825
|
-
validationToRule(
|
826
|
-
{
|
827
|
-
ruleId: "known-argument-names",
|
828
|
-
rule: KnownArgumentNamesRule,
|
829
|
-
hasDidYouMeanSuggestions: !0
|
830
|
-
},
|
831
|
-
{
|
832
|
-
category: ["Schema", "Operations"],
|
833
|
-
description: "A GraphQL field is only valid if all supplied arguments are defined by that field.",
|
834
|
-
requiresSchema: !0
|
835
|
-
}
|
836
|
-
),
|
837
|
-
validationToRule(
|
838
|
-
{
|
839
|
-
ruleId: "known-directives",
|
840
|
-
rule: KnownDirectivesRule,
|
841
|
-
getDocumentNode({ context, node: documentNode }) {
|
842
|
-
let { ignoreClientDirectives = [] } = context.options[0] || {};
|
843
|
-
if (ignoreClientDirectives.length === 0)
|
844
|
-
return documentNode;
|
845
|
-
let filterDirectives = (node) => ({
|
846
|
-
...node,
|
847
|
-
directives: node.directives?.filter(
|
848
|
-
(directive) => !ignoreClientDirectives.includes(directive.name.value)
|
849
|
-
)
|
850
|
-
});
|
851
|
-
return visit3(documentNode, {
|
852
|
-
Field: filterDirectives,
|
853
|
-
OperationDefinition: filterDirectives
|
854
|
-
});
|
784
|
+
values: {
|
785
|
+
type: "boolean",
|
786
|
+
description: "Values of `enum`."
|
855
787
|
},
|
856
|
-
|
857
|
-
|
858
|
-
|
788
|
+
selections: {
|
789
|
+
...ARRAY_DEFAULT_OPTIONS,
|
790
|
+
items: {
|
791
|
+
enum: selectionsEnum
|
792
|
+
},
|
793
|
+
description: "Selections of `fragment` and operations `query`, `mutation` and `subscription`."
|
794
|
+
},
|
795
|
+
variables: {
|
796
|
+
type: "boolean",
|
797
|
+
description: "Variables of operations `query`, `mutation` and `subscription`."
|
798
|
+
},
|
799
|
+
arguments: {
|
800
|
+
...ARRAY_DEFAULT_OPTIONS,
|
801
|
+
items: {
|
802
|
+
enum: argumentsEnum
|
803
|
+
},
|
804
|
+
description: "Arguments of fields and directives."
|
805
|
+
},
|
806
|
+
definitions: {
|
807
|
+
type: "boolean",
|
808
|
+
description: "Definitions \u2013 `type`, `interface`, `enum`, `scalar`, `input`, `union` and `directive`."
|
809
|
+
},
|
810
|
+
groups: {
|
811
|
+
...ARRAY_DEFAULT_OPTIONS,
|
812
|
+
minItems: 2,
|
813
|
+
description: "Custom order group. Example: `['id', '*', 'createdAt', 'updatedAt']` where `*` says for everything else."
|
814
|
+
}
|
815
|
+
}
|
816
|
+
}
|
817
|
+
}, rule = {
|
818
|
+
meta: {
|
819
|
+
type: "suggestion",
|
820
|
+
fixable: "code",
|
821
|
+
docs: {
|
822
|
+
category: ["Schema", "Operations"],
|
823
|
+
description: "Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation selections and more.",
|
824
|
+
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
825
|
+
examples: [
|
826
|
+
{
|
827
|
+
title: "Incorrect",
|
828
|
+
usage: [{ fields: [Kind4.OBJECT_TYPE_DEFINITION] }],
|
829
|
+
code: (
|
830
|
+
/* GraphQL */
|
831
|
+
`
|
832
|
+
type User {
|
833
|
+
password: String
|
834
|
+
firstName: String! # should be before "password"
|
835
|
+
age: Int # should be before "firstName"
|
836
|
+
lastName: String!
|
837
|
+
}
|
838
|
+
`
|
839
|
+
)
|
840
|
+
},
|
841
|
+
{
|
842
|
+
title: "Correct",
|
843
|
+
usage: [{ fields: [Kind4.OBJECT_TYPE_DEFINITION] }],
|
844
|
+
code: (
|
845
|
+
/* GraphQL */
|
846
|
+
`
|
847
|
+
type User {
|
848
|
+
age: Int
|
849
|
+
firstName: String!
|
850
|
+
lastName: String!
|
851
|
+
password: String
|
852
|
+
}
|
853
|
+
`
|
854
|
+
)
|
855
|
+
},
|
856
|
+
{
|
857
|
+
title: "Incorrect",
|
858
|
+
usage: [{ values: !0 }],
|
859
|
+
code: (
|
860
|
+
/* GraphQL */
|
861
|
+
`
|
862
|
+
enum Role {
|
863
|
+
SUPER_ADMIN
|
864
|
+
ADMIN # should be before "SUPER_ADMIN"
|
865
|
+
USER
|
866
|
+
GOD # should be before "USER"
|
867
|
+
}
|
868
|
+
`
|
869
|
+
)
|
870
|
+
},
|
871
|
+
{
|
872
|
+
title: "Correct",
|
873
|
+
usage: [{ values: !0 }],
|
874
|
+
code: (
|
875
|
+
/* GraphQL */
|
876
|
+
`
|
877
|
+
enum Role {
|
878
|
+
ADMIN
|
879
|
+
GOD
|
880
|
+
SUPER_ADMIN
|
881
|
+
USER
|
882
|
+
}
|
883
|
+
`
|
884
|
+
)
|
885
|
+
},
|
886
|
+
{
|
887
|
+
title: "Incorrect",
|
888
|
+
usage: [{ selections: [Kind4.OPERATION_DEFINITION] }],
|
889
|
+
code: (
|
890
|
+
/* GraphQL */
|
891
|
+
`
|
892
|
+
query {
|
893
|
+
me {
|
894
|
+
firstName
|
895
|
+
lastName
|
896
|
+
email # should be before "lastName"
|
897
|
+
}
|
898
|
+
}
|
899
|
+
`
|
900
|
+
)
|
901
|
+
},
|
902
|
+
{
|
903
|
+
title: "Correct",
|
904
|
+
usage: [{ selections: [Kind4.OPERATION_DEFINITION] }],
|
905
|
+
code: (
|
906
|
+
/* GraphQL */
|
907
|
+
`
|
908
|
+
query {
|
909
|
+
me {
|
910
|
+
email
|
911
|
+
firstName
|
912
|
+
lastName
|
913
|
+
}
|
914
|
+
}
|
915
|
+
`
|
916
|
+
)
|
917
|
+
}
|
918
|
+
],
|
919
|
+
configOptions: {
|
920
|
+
schema: [
|
921
|
+
{
|
922
|
+
definitions: !0,
|
923
|
+
fields: fieldsEnum,
|
924
|
+
values: !0,
|
925
|
+
arguments: argumentsEnum,
|
926
|
+
groups: ["id", "*", "createdAt", "updatedAt"]
|
927
|
+
}
|
928
|
+
],
|
929
|
+
operations: [
|
930
|
+
{
|
931
|
+
definitions: !0,
|
932
|
+
selections: selectionsEnum,
|
933
|
+
variables: !0,
|
934
|
+
arguments: [Kind4.FIELD, Kind4.DIRECTIVE],
|
935
|
+
groups: ["id", "*", "createdAt", "updatedAt"]
|
936
|
+
}
|
937
|
+
]
|
938
|
+
}
|
939
|
+
},
|
940
|
+
messages: {
|
941
|
+
[RULE_ID]: "{{ currNode }} should be before {{ prevNode }}"
|
942
|
+
},
|
943
|
+
schema
|
944
|
+
},
|
945
|
+
create(context) {
|
946
|
+
let sourceCode = context.getSourceCode();
|
947
|
+
function isNodeAndCommentOnSameLine(node, comment) {
|
948
|
+
return node.loc.end.line === comment.loc.start.line;
|
949
|
+
}
|
950
|
+
function getBeforeComments(node) {
|
951
|
+
let commentsBefore = sourceCode.getCommentsBefore(node);
|
952
|
+
if (commentsBefore.length === 0)
|
953
|
+
return [];
|
954
|
+
let tokenBefore = sourceCode.getTokenBefore(node);
|
955
|
+
if (tokenBefore)
|
956
|
+
return commentsBefore.filter((comment) => !isNodeAndCommentOnSameLine(tokenBefore, comment));
|
957
|
+
let filteredComments = [], nodeLine = node.loc.start.line;
|
958
|
+
for (let i = commentsBefore.length - 1; i >= 0; i -= 1) {
|
959
|
+
let comment = commentsBefore[i];
|
960
|
+
if (nodeLine - comment.loc.start.line - filteredComments.length > 1)
|
961
|
+
break;
|
962
|
+
filteredComments.unshift(comment);
|
963
|
+
}
|
964
|
+
return filteredComments;
|
965
|
+
}
|
966
|
+
function getRangeWithComments(node) {
|
967
|
+
node.kind === Kind4.VARIABLE && (node = node.parent);
|
968
|
+
let [firstBeforeComment] = getBeforeComments(node), [firstAfterComment] = sourceCode.getCommentsAfter(node), from = firstBeforeComment || node, to = firstAfterComment && isNodeAndCommentOnSameLine(node, firstAfterComment) ? firstAfterComment : node;
|
969
|
+
return [from.range[0], to.range[1]];
|
970
|
+
}
|
971
|
+
function checkNodes(nodes = []) {
|
972
|
+
for (let i = 1; i < nodes.length; i += 1) {
|
973
|
+
let currNode = nodes[i], currName = "alias" in currNode && currNode.alias?.value || "name" in currNode && currNode.name?.value;
|
974
|
+
if (!currName)
|
975
|
+
continue;
|
976
|
+
let prevNode = nodes[i - 1], prevName = "alias" in prevNode && prevNode.alias?.value || "name" in prevNode && prevNode.name?.value;
|
977
|
+
if (prevName) {
|
978
|
+
let compareResult = prevName.localeCompare(currName), { groups } = opts, shouldSortByGroup = !1;
|
979
|
+
if (groups?.length) {
|
980
|
+
if (!groups.includes("*"))
|
981
|
+
throw new Error("`groups` option should contain `*` string.");
|
982
|
+
let indexForPrev = groups.indexOf(prevName);
|
983
|
+
indexForPrev === -1 && (indexForPrev = groups.indexOf("*"));
|
984
|
+
let indexForCurr = groups.indexOf(currName);
|
985
|
+
if (indexForCurr === -1 && (indexForCurr = groups.indexOf("*")), shouldSortByGroup = indexForPrev - indexForCurr > 0, indexForPrev < indexForCurr)
|
986
|
+
continue;
|
987
|
+
}
|
988
|
+
if (!shouldSortByGroup && !(compareResult === 1) && (!(compareResult === 0) || !prevNode.kind.endsWith("Extension") || currNode.kind.endsWith("Extension")))
|
989
|
+
continue;
|
990
|
+
}
|
991
|
+
context.report({
|
992
|
+
// @ts-expect-error can't be undefined
|
993
|
+
node: "alias" in currNode && currNode.alias || currNode.name,
|
994
|
+
messageId: RULE_ID,
|
995
|
+
data: {
|
996
|
+
currNode: displayNodeName(currNode),
|
997
|
+
prevNode: prevName ? displayNodeName(prevNode) : lowerCase2(prevNode.kind)
|
998
|
+
},
|
999
|
+
*fix(fixer) {
|
1000
|
+
let prevRange = getRangeWithComments(prevNode), currRange = getRangeWithComments(currNode);
|
1001
|
+
yield fixer.replaceTextRange(
|
1002
|
+
prevRange,
|
1003
|
+
sourceCode.getText({ range: currRange })
|
1004
|
+
), yield fixer.replaceTextRange(
|
1005
|
+
currRange,
|
1006
|
+
sourceCode.getText({ range: prevRange })
|
1007
|
+
);
|
1008
|
+
}
|
1009
|
+
});
|
1010
|
+
}
|
1011
|
+
}
|
1012
|
+
let opts = context.options[0], fields = new Set(opts.fields ?? []), listeners = {}, fieldsSelector = [
|
1013
|
+
fields.has(Kind4.OBJECT_TYPE_DEFINITION) && [
|
1014
|
+
Kind4.OBJECT_TYPE_DEFINITION,
|
1015
|
+
Kind4.OBJECT_TYPE_EXTENSION
|
1016
|
+
],
|
1017
|
+
fields.has(Kind4.INTERFACE_TYPE_DEFINITION) && [
|
1018
|
+
Kind4.INTERFACE_TYPE_DEFINITION,
|
1019
|
+
Kind4.INTERFACE_TYPE_EXTENSION
|
1020
|
+
],
|
1021
|
+
fields.has(Kind4.INPUT_OBJECT_TYPE_DEFINITION) && [
|
1022
|
+
Kind4.INPUT_OBJECT_TYPE_DEFINITION,
|
1023
|
+
Kind4.INPUT_OBJECT_TYPE_EXTENSION
|
1024
|
+
]
|
1025
|
+
].filter(truthy).flat().join(","), selectionsSelector = opts.selections?.join(","), argumentsSelector = opts.arguments?.join(",");
|
1026
|
+
if (fieldsSelector && (listeners[fieldsSelector] = (node) => {
|
1027
|
+
checkNodes(node.fields);
|
1028
|
+
}), opts.values) {
|
1029
|
+
let enumValuesSelector = [Kind4.ENUM_TYPE_DEFINITION, Kind4.ENUM_TYPE_EXTENSION].join(",");
|
1030
|
+
listeners[enumValuesSelector] = (node) => {
|
1031
|
+
checkNodes(node.values);
|
1032
|
+
};
|
1033
|
+
}
|
1034
|
+
return selectionsSelector && (listeners[`:matches(${selectionsSelector}) SelectionSet`] = (node) => {
|
1035
|
+
checkNodes(node.selections);
|
1036
|
+
}), opts.variables && (listeners.OperationDefinition = (node) => {
|
1037
|
+
checkNodes(node.variableDefinitions?.map((varDef) => varDef.variable));
|
1038
|
+
}), argumentsSelector && (listeners[argumentsSelector] = (node) => {
|
1039
|
+
checkNodes(node.arguments);
|
1040
|
+
}), opts.definitions && (listeners.Document = (node) => {
|
1041
|
+
checkNodes(node.definitions);
|
1042
|
+
}), listeners;
|
1043
|
+
}
|
1044
|
+
};
|
1045
|
+
|
1046
|
+
// src/rules/description-style.ts
|
1047
|
+
var schema2 = {
|
1048
|
+
type: "array",
|
1049
|
+
maxItems: 1,
|
1050
|
+
items: {
|
1051
|
+
type: "object",
|
1052
|
+
additionalProperties: !1,
|
1053
|
+
minProperties: 1,
|
1054
|
+
properties: {
|
1055
|
+
style: {
|
1056
|
+
enum: ["block", "inline"],
|
1057
|
+
default: "block"
|
1058
|
+
}
|
1059
|
+
}
|
1060
|
+
}
|
1061
|
+
}, rule2 = {
|
1062
|
+
meta: {
|
1063
|
+
type: "suggestion",
|
1064
|
+
hasSuggestions: !0,
|
1065
|
+
docs: {
|
1066
|
+
examples: [
|
1067
|
+
{
|
1068
|
+
title: "Incorrect",
|
1069
|
+
usage: [{ style: "inline" }],
|
1070
|
+
code: (
|
1071
|
+
/* GraphQL */
|
1072
|
+
`
|
1073
|
+
""" Description """
|
1074
|
+
type someTypeName {
|
1075
|
+
# ...
|
1076
|
+
}
|
1077
|
+
`
|
1078
|
+
)
|
1079
|
+
},
|
1080
|
+
{
|
1081
|
+
title: "Correct",
|
1082
|
+
usage: [{ style: "inline" }],
|
1083
|
+
code: (
|
1084
|
+
/* GraphQL */
|
1085
|
+
`
|
1086
|
+
" Description "
|
1087
|
+
type someTypeName {
|
1088
|
+
# ...
|
1089
|
+
}
|
1090
|
+
`
|
1091
|
+
)
|
1092
|
+
}
|
1093
|
+
],
|
1094
|
+
description: "Require all comments to follow the same style (either block or inline).",
|
1095
|
+
category: "Schema",
|
1096
|
+
url: "https://the-guild.dev/graphql/eslint/rules/description-style",
|
1097
|
+
recommended: !0
|
1098
|
+
},
|
1099
|
+
schema: schema2
|
1100
|
+
},
|
1101
|
+
create(context) {
|
1102
|
+
let { style = "block" } = context.options[0] || {}, isBlock = style === "block";
|
1103
|
+
return {
|
1104
|
+
[`.description[type=StringValue][block!=${isBlock}]`](node) {
|
1105
|
+
context.report({
|
1106
|
+
loc: isBlock ? node.loc : node.loc.start,
|
1107
|
+
message: `Unexpected ${isBlock ? "inline" : "block"} description for ${getNodeName(
|
1108
|
+
node.parent
|
1109
|
+
)}`,
|
1110
|
+
suggest: [
|
1111
|
+
{
|
1112
|
+
desc: `Change to ${isBlock ? "block" : "inline"} style description`,
|
1113
|
+
fix(fixer) {
|
1114
|
+
let originalText = context.getSourceCode().getText(node), newText = isBlock ? originalText.replace(/(^")|("$)/g, '"""') : originalText.replace(/(^""")|("""$)/g, '"').replace(/\s+/g, " ");
|
1115
|
+
return fixer.replaceText(node, newText);
|
1116
|
+
}
|
1117
|
+
}
|
1118
|
+
]
|
1119
|
+
});
|
1120
|
+
}
|
1121
|
+
};
|
1122
|
+
}
|
1123
|
+
};
|
1124
|
+
|
1125
|
+
// src/rules/graphql-js-validation.ts
|
1126
|
+
import {
|
1127
|
+
Kind as Kind5,
|
1128
|
+
validate,
|
1129
|
+
visit as visit3
|
1130
|
+
} from "graphql";
|
1131
|
+
import {
|
1132
|
+
ExecutableDefinitionsRule,
|
1133
|
+
FieldsOnCorrectTypeRule,
|
1134
|
+
FragmentsOnCompositeTypesRule,
|
1135
|
+
KnownArgumentNamesRule,
|
1136
|
+
KnownDirectivesRule,
|
1137
|
+
KnownFragmentNamesRule,
|
1138
|
+
KnownTypeNamesRule,
|
1139
|
+
LoneAnonymousOperationRule,
|
1140
|
+
LoneSchemaDefinitionRule,
|
1141
|
+
NoFragmentCyclesRule,
|
1142
|
+
NoUndefinedVariablesRule,
|
1143
|
+
NoUnusedFragmentsRule,
|
1144
|
+
NoUnusedVariablesRule,
|
1145
|
+
OverlappingFieldsCanBeMergedRule,
|
1146
|
+
PossibleFragmentSpreadsRule,
|
1147
|
+
PossibleTypeExtensionsRule,
|
1148
|
+
ProvidedRequiredArgumentsRule,
|
1149
|
+
ScalarLeafsRule,
|
1150
|
+
SingleFieldSubscriptionsRule,
|
1151
|
+
UniqueArgumentNamesRule,
|
1152
|
+
UniqueDirectiveNamesRule,
|
1153
|
+
UniqueDirectivesPerLocationRule,
|
1154
|
+
UniqueFieldDefinitionNamesRule,
|
1155
|
+
UniqueInputFieldNamesRule,
|
1156
|
+
UniqueOperationTypesRule,
|
1157
|
+
UniqueTypeNamesRule,
|
1158
|
+
UniqueVariableNamesRule,
|
1159
|
+
ValuesOfCorrectTypeRule,
|
1160
|
+
VariablesAreInputTypesRule,
|
1161
|
+
VariablesInAllowedPositionRule
|
1162
|
+
} from "graphql/validation/index.js";
|
1163
|
+
import { validateSDL } from "graphql/validation/validate.js";
|
1164
|
+
function validateDocument({
|
1165
|
+
context,
|
1166
|
+
schema: schema15 = null,
|
1167
|
+
documentNode,
|
1168
|
+
rule: rule35,
|
1169
|
+
hasDidYouMeanSuggestions
|
1170
|
+
}) {
|
1171
|
+
if (documentNode.definitions.length !== 0)
|
1172
|
+
try {
|
1173
|
+
let validationErrors = schema15 ? validate(schema15, documentNode, [rule35]) : validateSDL(documentNode, null, [rule35]);
|
1174
|
+
for (let error of validationErrors) {
|
1175
|
+
let { line, column } = error.locations[0], sourceCode = context.getSourceCode(), { tokens } = sourceCode.ast, token = tokens.find(
|
1176
|
+
(token2) => token2.loc.start.line === line && token2.loc.start.column === column - 1
|
1177
|
+
), loc = {
|
1178
|
+
line,
|
1179
|
+
column: column - 1
|
1180
|
+
};
|
1181
|
+
token && (loc = // if cursor on `@` symbol than use next node
|
1182
|
+
token.type === "@" ? sourceCode.getNodeByRangeIndex(token.range[1] + 1).loc : token.loc);
|
1183
|
+
let didYouMeanContent = error.message.match(/Did you mean (?<content>.*)\?$/)?.groups.content, matches = didYouMeanContent ? [...didYouMeanContent.matchAll(/"(?<name>[^"]*)"/g)] : [];
|
1184
|
+
context.report({
|
1185
|
+
loc,
|
1186
|
+
message: error.message,
|
1187
|
+
suggest: hasDidYouMeanSuggestions ? matches.map((match) => {
|
1188
|
+
let { name: name2 } = match.groups;
|
1189
|
+
return {
|
1190
|
+
desc: `Rename to \`${name2}\``,
|
1191
|
+
fix: (fixer) => fixer.replaceText(token, name2)
|
1192
|
+
};
|
1193
|
+
}) : []
|
1194
|
+
});
|
1195
|
+
}
|
1196
|
+
} catch (error) {
|
1197
|
+
context.report({
|
1198
|
+
loc: REPORT_ON_FIRST_CHARACTER,
|
1199
|
+
message: error.message
|
1200
|
+
});
|
1201
|
+
}
|
1202
|
+
}
|
1203
|
+
var getFragmentDefsAndFragmentSpreads = (node) => {
|
1204
|
+
let fragmentDefs = /* @__PURE__ */ new Set(), fragmentSpreads = /* @__PURE__ */ new Set();
|
1205
|
+
return visit3(node, {
|
1206
|
+
FragmentDefinition(node2) {
|
1207
|
+
fragmentDefs.add(node2.name.value);
|
1208
|
+
},
|
1209
|
+
FragmentSpread(node2) {
|
1210
|
+
fragmentSpreads.add(node2.name.value);
|
1211
|
+
}
|
1212
|
+
}), { fragmentDefs, fragmentSpreads };
|
1213
|
+
}, getMissingFragments = (node) => {
|
1214
|
+
let { fragmentDefs, fragmentSpreads } = getFragmentDefsAndFragmentSpreads(node);
|
1215
|
+
return [...fragmentSpreads].filter((name2) => !fragmentDefs.has(name2));
|
1216
|
+
}, handleMissingFragments = ({ ruleId, context, node }) => {
|
1217
|
+
let missingFragments = getMissingFragments(node);
|
1218
|
+
if (missingFragments.length > 0) {
|
1219
|
+
let siblings = requireSiblingsOperations(ruleId, context), fragmentsToAdd = [];
|
1220
|
+
for (let fragmentName of missingFragments) {
|
1221
|
+
let [foundFragment] = siblings.getFragment(fragmentName).map((source) => source.document);
|
1222
|
+
foundFragment && fragmentsToAdd.push(foundFragment);
|
1223
|
+
}
|
1224
|
+
if (fragmentsToAdd.length > 0)
|
1225
|
+
return handleMissingFragments({
|
1226
|
+
ruleId,
|
1227
|
+
context,
|
1228
|
+
node: {
|
1229
|
+
kind: Kind5.DOCUMENT,
|
1230
|
+
definitions: [...node.definitions, ...fragmentsToAdd]
|
1231
|
+
}
|
1232
|
+
});
|
1233
|
+
}
|
1234
|
+
return node;
|
1235
|
+
}, validationToRule = ({
|
1236
|
+
ruleId,
|
1237
|
+
rule: rule35,
|
1238
|
+
getDocumentNode,
|
1239
|
+
schema: schema15 = [],
|
1240
|
+
hasDidYouMeanSuggestions
|
1241
|
+
}, docs) => ({
|
1242
|
+
[ruleId]: {
|
1243
|
+
meta: {
|
1244
|
+
docs: {
|
1245
|
+
recommended: !0,
|
1246
|
+
...docs,
|
1247
|
+
graphQLJSRuleName: rule35.name,
|
1248
|
+
url: `https://the-guild.dev/graphql/eslint/rules/${ruleId}`,
|
1249
|
+
description: `${docs.description}
|
1250
|
+
> This rule is a wrapper around a \`graphql-js\` validation function.`
|
1251
|
+
},
|
1252
|
+
schema: schema15,
|
1253
|
+
hasSuggestions: hasDidYouMeanSuggestions
|
1254
|
+
},
|
1255
|
+
create(context) {
|
1256
|
+
return {
|
1257
|
+
Document(node) {
|
1258
|
+
let schema16 = docs.requiresSchema ? requireGraphQLSchemaFromContext(ruleId, context) : null, documentNode = getDocumentNode ? getDocumentNode({ ruleId, context, node: node.rawNode() }) : node.rawNode();
|
1259
|
+
validateDocument({
|
1260
|
+
context,
|
1261
|
+
schema: schema16,
|
1262
|
+
documentNode,
|
1263
|
+
rule: rule35,
|
1264
|
+
hasDidYouMeanSuggestions
|
1265
|
+
});
|
1266
|
+
}
|
1267
|
+
};
|
1268
|
+
}
|
1269
|
+
}
|
1270
|
+
}), GRAPHQL_JS_VALIDATIONS = Object.assign(
|
1271
|
+
{},
|
1272
|
+
validationToRule(
|
1273
|
+
{
|
1274
|
+
ruleId: "executable-definitions",
|
1275
|
+
rule: ExecutableDefinitionsRule
|
1276
|
+
},
|
1277
|
+
{
|
1278
|
+
category: "Operations",
|
1279
|
+
description: "A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.",
|
1280
|
+
requiresSchema: !0
|
1281
|
+
}
|
1282
|
+
),
|
1283
|
+
validationToRule(
|
1284
|
+
{
|
1285
|
+
ruleId: "fields-on-correct-type",
|
1286
|
+
rule: FieldsOnCorrectTypeRule,
|
1287
|
+
hasDidYouMeanSuggestions: !0
|
1288
|
+
},
|
1289
|
+
{
|
1290
|
+
category: "Operations",
|
1291
|
+
description: "A GraphQL document is only valid if all fields selected are defined by the parent type, or are an allowed meta field such as `__typename`.",
|
1292
|
+
requiresSchema: !0
|
1293
|
+
}
|
1294
|
+
),
|
1295
|
+
validationToRule(
|
1296
|
+
{
|
1297
|
+
ruleId: "fragments-on-composite-type",
|
1298
|
+
rule: FragmentsOnCompositeTypesRule
|
1299
|
+
},
|
1300
|
+
{
|
1301
|
+
category: "Operations",
|
1302
|
+
description: "Fragments use a type condition to determine if they apply, since fragments can only be spread into a composite type (object, interface, or union), the type condition must also be a composite type.",
|
1303
|
+
requiresSchema: !0
|
1304
|
+
}
|
1305
|
+
),
|
1306
|
+
validationToRule(
|
1307
|
+
{
|
1308
|
+
ruleId: "known-argument-names",
|
1309
|
+
rule: KnownArgumentNamesRule,
|
1310
|
+
hasDidYouMeanSuggestions: !0
|
1311
|
+
},
|
1312
|
+
{
|
1313
|
+
category: ["Schema", "Operations"],
|
1314
|
+
description: "A GraphQL field is only valid if all supplied arguments are defined by that field.",
|
1315
|
+
requiresSchema: !0
|
1316
|
+
}
|
1317
|
+
),
|
1318
|
+
validationToRule(
|
1319
|
+
{
|
1320
|
+
ruleId: "known-directives",
|
1321
|
+
rule: KnownDirectivesRule,
|
1322
|
+
getDocumentNode({ context, node: documentNode }) {
|
1323
|
+
let { ignoreClientDirectives = [] } = context.options[0] || {};
|
1324
|
+
if (ignoreClientDirectives.length === 0)
|
1325
|
+
return documentNode;
|
1326
|
+
let filterDirectives = (node) => ({
|
1327
|
+
...node,
|
1328
|
+
directives: node.directives?.filter(
|
1329
|
+
(directive) => !ignoreClientDirectives.includes(directive.name.value)
|
1330
|
+
)
|
1331
|
+
});
|
1332
|
+
return visit3(documentNode, {
|
1333
|
+
Field: filterDirectives,
|
1334
|
+
OperationDefinition: filterDirectives
|
1335
|
+
});
|
1336
|
+
},
|
1337
|
+
schema: {
|
1338
|
+
type: "array",
|
1339
|
+
maxItems: 1,
|
859
1340
|
items: {
|
860
1341
|
type: "object",
|
861
1342
|
additionalProperties: !1,
|
@@ -1028,13 +1509,13 @@ var getFragmentDefsAndFragmentSpreads = (node) => {
|
|
1028
1509
|
delete FilePathToDocumentsMap[currentFilePath];
|
1029
1510
|
for (let [filePath, documents] of Object.entries(FilePathToDocumentsMap))
|
1030
1511
|
if (getMissingFragments({
|
1031
|
-
kind:
|
1512
|
+
kind: Kind5.DOCUMENT,
|
1032
1513
|
definitions: documents
|
1033
1514
|
}).some(
|
1034
1515
|
(fragment) => fragmentDefs.has(fragment)
|
1035
1516
|
))
|
1036
1517
|
return getParentNode(filePath, {
|
1037
|
-
kind:
|
1518
|
+
kind: Kind5.DOCUMENT,
|
1038
1519
|
definitions: [...node2.definitions, ...documents]
|
1039
1520
|
});
|
1040
1521
|
return node2;
|
@@ -1043,586 +1524,212 @@ var getFragmentDefsAndFragmentSpreads = (node) => {
|
|
1043
1524
|
}
|
1044
1525
|
},
|
1045
1526
|
{
|
1046
|
-
category: "Operations",
|
1047
|
-
description: "A GraphQL document is only valid if all fragment definitions are spread within operations, or spread within other fragments spread within operations.",
|
1048
|
-
requiresSchema: !0,
|
1049
|
-
requiresSiblings: !0
|
1050
|
-
}
|
1051
|
-
),
|
1052
|
-
validationToRule(
|
1053
|
-
{
|
1054
|
-
ruleId: "no-unused-variables",
|
1055
|
-
rule: NoUnusedVariablesRule,
|
1056
|
-
getDocumentNode: handleMissingFragments
|
1057
|
-
},
|
1058
|
-
{
|
1059
|
-
category: "Operations",
|
1060
|
-
description: "A GraphQL operation is only valid if all variables defined by an operation are used, either directly or within a spread fragment.",
|
1061
|
-
requiresSchema: !0,
|
1062
|
-
requiresSiblings: !0
|
1063
|
-
}
|
1064
|
-
),
|
1065
|
-
validationToRule(
|
1066
|
-
{
|
1067
|
-
ruleId: "overlapping-fields-can-be-merged",
|
1068
|
-
rule: OverlappingFieldsCanBeMergedRule
|
1069
|
-
},
|
1070
|
-
{
|
1071
|
-
category: "Operations",
|
1072
|
-
description: "A selection set is only valid if all fields (including spreading any fragments) either correspond to distinct response names or can be merged without ambiguity.",
|
1073
|
-
requiresSchema: !0
|
1074
|
-
}
|
1075
|
-
),
|
1076
|
-
validationToRule(
|
1077
|
-
{
|
1078
|
-
ruleId: "possible-fragment-spread",
|
1079
|
-
rule: PossibleFragmentSpreadsRule
|
1080
|
-
},
|
1081
|
-
{
|
1082
|
-
category: "Operations",
|
1083
|
-
description: "A fragment spread is only valid if the type condition could ever possibly be true: if there is a non-empty intersection of the possible parent types, and possible types which pass the type condition.",
|
1084
|
-
requiresSchema: !0
|
1085
|
-
}
|
1086
|
-
),
|
1087
|
-
validationToRule(
|
1088
|
-
{
|
1089
|
-
ruleId: "possible-type-extension",
|
1090
|
-
rule: PossibleTypeExtensionsRule,
|
1091
|
-
hasDidYouMeanSuggestions: !0
|
1092
|
-
},
|
1093
|
-
{
|
1094
|
-
category: "Schema",
|
1095
|
-
description: "A type extension is only valid if the type is defined and has the same kind.",
|
1096
|
-
recommended: !0,
|
1097
|
-
requiresSchema: !0
|
1098
|
-
}
|
1099
|
-
),
|
1100
|
-
validationToRule(
|
1101
|
-
{
|
1102
|
-
ruleId: "provided-required-arguments",
|
1103
|
-
rule: ProvidedRequiredArgumentsRule
|
1104
|
-
},
|
1105
|
-
{
|
1106
|
-
category: ["Schema", "Operations"],
|
1107
|
-
description: "A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.",
|
1108
|
-
requiresSchema: !0
|
1109
|
-
}
|
1110
|
-
),
|
1111
|
-
validationToRule(
|
1112
|
-
{
|
1113
|
-
ruleId: "scalar-leafs",
|
1114
|
-
rule: ScalarLeafsRule,
|
1115
|
-
hasDidYouMeanSuggestions: !0
|
1116
|
-
},
|
1117
|
-
{
|
1118
|
-
category: "Operations",
|
1119
|
-
description: "A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.",
|
1120
|
-
requiresSchema: !0
|
1121
|
-
}
|
1122
|
-
),
|
1123
|
-
validationToRule(
|
1124
|
-
{
|
1125
|
-
ruleId: "one-field-subscriptions",
|
1126
|
-
rule: SingleFieldSubscriptionsRule
|
1127
|
-
},
|
1128
|
-
{
|
1129
|
-
category: "Operations",
|
1130
|
-
description: "A GraphQL subscription is valid only if it contains a single root field.",
|
1131
|
-
requiresSchema: !0
|
1132
|
-
}
|
1133
|
-
),
|
1134
|
-
validationToRule(
|
1135
|
-
{
|
1136
|
-
ruleId: "unique-argument-names",
|
1137
|
-
rule: UniqueArgumentNamesRule
|
1138
|
-
},
|
1139
|
-
{
|
1140
|
-
category: "Operations",
|
1141
|
-
description: "A GraphQL field or directive is only valid if all supplied arguments are uniquely named.",
|
1142
|
-
requiresSchema: !0
|
1143
|
-
}
|
1144
|
-
),
|
1145
|
-
validationToRule(
|
1146
|
-
{
|
1147
|
-
ruleId: "unique-directive-names",
|
1148
|
-
rule: UniqueDirectiveNamesRule
|
1149
|
-
},
|
1150
|
-
{
|
1151
|
-
category: "Schema",
|
1152
|
-
description: "A GraphQL document is only valid if all defined directives have unique names."
|
1153
|
-
}
|
1154
|
-
),
|
1155
|
-
validationToRule(
|
1156
|
-
{
|
1157
|
-
ruleId: "unique-directive-names-per-location",
|
1158
|
-
rule: UniqueDirectivesPerLocationRule
|
1159
|
-
},
|
1160
|
-
{
|
1161
|
-
category: ["Schema", "Operations"],
|
1162
|
-
description: "A GraphQL document is only valid if all non-repeatable directives at a given location are uniquely named.",
|
1163
|
-
requiresSchema: !0
|
1527
|
+
category: "Operations",
|
1528
|
+
description: "A GraphQL document is only valid if all fragment definitions are spread within operations, or spread within other fragments spread within operations.",
|
1529
|
+
requiresSchema: !0,
|
1530
|
+
requiresSiblings: !0
|
1164
1531
|
}
|
1165
1532
|
),
|
1166
1533
|
validationToRule(
|
1167
1534
|
{
|
1168
|
-
ruleId: "
|
1169
|
-
rule:
|
1535
|
+
ruleId: "no-unused-variables",
|
1536
|
+
rule: NoUnusedVariablesRule,
|
1537
|
+
getDocumentNode: handleMissingFragments
|
1170
1538
|
},
|
1171
1539
|
{
|
1172
|
-
category: "
|
1173
|
-
description: "A GraphQL
|
1540
|
+
category: "Operations",
|
1541
|
+
description: "A GraphQL operation is only valid if all variables defined by an operation are used, either directly or within a spread fragment.",
|
1542
|
+
requiresSchema: !0,
|
1543
|
+
requiresSiblings: !0
|
1174
1544
|
}
|
1175
1545
|
),
|
1176
1546
|
validationToRule(
|
1177
1547
|
{
|
1178
|
-
ruleId: "
|
1179
|
-
rule:
|
1548
|
+
ruleId: "overlapping-fields-can-be-merged",
|
1549
|
+
rule: OverlappingFieldsCanBeMergedRule
|
1180
1550
|
},
|
1181
1551
|
{
|
1182
1552
|
category: "Operations",
|
1183
|
-
description: "A
|
1553
|
+
description: "A selection set is only valid if all fields (including spreading any fragments) either correspond to distinct response names or can be merged without ambiguity.",
|
1554
|
+
requiresSchema: !0
|
1184
1555
|
}
|
1185
1556
|
),
|
1186
1557
|
validationToRule(
|
1187
1558
|
{
|
1188
|
-
ruleId: "
|
1189
|
-
rule:
|
1559
|
+
ruleId: "possible-fragment-spread",
|
1560
|
+
rule: PossibleFragmentSpreadsRule
|
1190
1561
|
},
|
1191
1562
|
{
|
1192
|
-
category: "
|
1193
|
-
description: "A
|
1563
|
+
category: "Operations",
|
1564
|
+
description: "A fragment spread is only valid if the type condition could ever possibly be true: if there is a non-empty intersection of the possible parent types, and possible types which pass the type condition.",
|
1565
|
+
requiresSchema: !0
|
1194
1566
|
}
|
1195
1567
|
),
|
1196
1568
|
validationToRule(
|
1197
1569
|
{
|
1198
|
-
ruleId: "
|
1199
|
-
rule:
|
1570
|
+
ruleId: "possible-type-extension",
|
1571
|
+
rule: PossibleTypeExtensionsRule,
|
1572
|
+
hasDidYouMeanSuggestions: !0
|
1200
1573
|
},
|
1201
1574
|
{
|
1202
1575
|
category: "Schema",
|
1203
|
-
description: "A
|
1576
|
+
description: "A type extension is only valid if the type is defined and has the same kind.",
|
1577
|
+
recommended: !0,
|
1578
|
+
requiresSchema: !0
|
1204
1579
|
}
|
1205
1580
|
),
|
1206
1581
|
validationToRule(
|
1207
1582
|
{
|
1208
|
-
ruleId: "
|
1209
|
-
rule:
|
1583
|
+
ruleId: "provided-required-arguments",
|
1584
|
+
rule: ProvidedRequiredArgumentsRule
|
1210
1585
|
},
|
1211
1586
|
{
|
1212
|
-
category: "Operations",
|
1213
|
-
description: "A
|
1587
|
+
category: ["Schema", "Operations"],
|
1588
|
+
description: "A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.",
|
1214
1589
|
requiresSchema: !0
|
1215
1590
|
}
|
1216
1591
|
),
|
1217
1592
|
validationToRule(
|
1218
1593
|
{
|
1219
|
-
ruleId: "
|
1220
|
-
rule:
|
1594
|
+
ruleId: "scalar-leafs",
|
1595
|
+
rule: ScalarLeafsRule,
|
1221
1596
|
hasDidYouMeanSuggestions: !0
|
1222
1597
|
},
|
1223
1598
|
{
|
1224
1599
|
category: "Operations",
|
1225
|
-
description: "A GraphQL document is only
|
1600
|
+
description: "A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.",
|
1226
1601
|
requiresSchema: !0
|
1227
1602
|
}
|
1228
1603
|
),
|
1229
1604
|
validationToRule(
|
1230
1605
|
{
|
1231
|
-
ruleId: "
|
1232
|
-
rule:
|
1606
|
+
ruleId: "one-field-subscriptions",
|
1607
|
+
rule: SingleFieldSubscriptionsRule
|
1233
1608
|
},
|
1234
1609
|
{
|
1235
1610
|
category: "Operations",
|
1236
|
-
description: "A GraphQL
|
1611
|
+
description: "A GraphQL subscription is valid only if it contains a single root field.",
|
1237
1612
|
requiresSchema: !0
|
1238
1613
|
}
|
1239
1614
|
),
|
1240
1615
|
validationToRule(
|
1241
1616
|
{
|
1242
|
-
ruleId: "
|
1243
|
-
rule:
|
1617
|
+
ruleId: "unique-argument-names",
|
1618
|
+
rule: UniqueArgumentNamesRule
|
1244
1619
|
},
|
1245
1620
|
{
|
1246
1621
|
category: "Operations",
|
1247
|
-
description: "
|
1622
|
+
description: "A GraphQL field or directive is only valid if all supplied arguments are uniquely named.",
|
1248
1623
|
requiresSchema: !0
|
1249
1624
|
}
|
1250
|
-
)
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
Kind5.OBJECT_TYPE_DEFINITION,
|
1260
|
-
Kind5.INTERFACE_TYPE_DEFINITION,
|
1261
|
-
Kind5.INPUT_OBJECT_TYPE_DEFINITION
|
1262
|
-
], selectionsEnum = [
|
1263
|
-
Kind5.OPERATION_DEFINITION,
|
1264
|
-
Kind5.FRAGMENT_DEFINITION
|
1265
|
-
], argumentsEnum = [
|
1266
|
-
Kind5.FIELD_DEFINITION,
|
1267
|
-
Kind5.FIELD,
|
1268
|
-
Kind5.DIRECTIVE_DEFINITION,
|
1269
|
-
Kind5.DIRECTIVE
|
1270
|
-
], schema = {
|
1271
|
-
type: "array",
|
1272
|
-
minItems: 1,
|
1273
|
-
maxItems: 1,
|
1274
|
-
items: {
|
1275
|
-
type: "object",
|
1276
|
-
additionalProperties: !1,
|
1277
|
-
minProperties: 1,
|
1278
|
-
properties: {
|
1279
|
-
fields: {
|
1280
|
-
...ARRAY_DEFAULT_OPTIONS,
|
1281
|
-
items: {
|
1282
|
-
enum: fieldsEnum
|
1283
|
-
},
|
1284
|
-
description: "Fields of `type`, `interface`, and `input`."
|
1285
|
-
},
|
1286
|
-
values: {
|
1287
|
-
type: "boolean",
|
1288
|
-
description: "Values of `enum`."
|
1289
|
-
},
|
1290
|
-
selections: {
|
1291
|
-
...ARRAY_DEFAULT_OPTIONS,
|
1292
|
-
items: {
|
1293
|
-
enum: selectionsEnum
|
1294
|
-
},
|
1295
|
-
description: "Selections of `fragment` and operations `query`, `mutation` and `subscription`."
|
1296
|
-
},
|
1297
|
-
variables: {
|
1298
|
-
type: "boolean",
|
1299
|
-
description: "Variables of operations `query`, `mutation` and `subscription`."
|
1300
|
-
},
|
1301
|
-
arguments: {
|
1302
|
-
...ARRAY_DEFAULT_OPTIONS,
|
1303
|
-
items: {
|
1304
|
-
enum: argumentsEnum
|
1305
|
-
},
|
1306
|
-
description: "Arguments of fields and directives."
|
1307
|
-
},
|
1308
|
-
definitions: {
|
1309
|
-
type: "boolean",
|
1310
|
-
description: "Definitions \u2013 `type`, `interface`, `enum`, `scalar`, `input`, `union` and `directive`."
|
1311
|
-
},
|
1312
|
-
groups: {
|
1313
|
-
...ARRAY_DEFAULT_OPTIONS,
|
1314
|
-
minItems: 2,
|
1315
|
-
description: "Custom order group. Example: `['id', '*', 'createdAt', 'updatedAt']` where `*` says for everything else."
|
1316
|
-
}
|
1625
|
+
),
|
1626
|
+
validationToRule(
|
1627
|
+
{
|
1628
|
+
ruleId: "unique-directive-names",
|
1629
|
+
rule: UniqueDirectiveNamesRule
|
1630
|
+
},
|
1631
|
+
{
|
1632
|
+
category: "Schema",
|
1633
|
+
description: "A GraphQL document is only valid if all defined directives have unique names."
|
1317
1634
|
}
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1635
|
+
),
|
1636
|
+
validationToRule(
|
1637
|
+
{
|
1638
|
+
ruleId: "unique-directive-names-per-location",
|
1639
|
+
rule: UniqueDirectivesPerLocationRule
|
1640
|
+
},
|
1641
|
+
{
|
1324
1642
|
category: ["Schema", "Operations"],
|
1325
|
-
description: "
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
`
|
1334
|
-
type User {
|
1335
|
-
password: String
|
1336
|
-
firstName: String! # should be before "password"
|
1337
|
-
age: Int # should be before "firstName"
|
1338
|
-
lastName: String!
|
1339
|
-
}
|
1340
|
-
`
|
1341
|
-
)
|
1342
|
-
},
|
1343
|
-
{
|
1344
|
-
title: "Correct",
|
1345
|
-
usage: [{ fields: [Kind5.OBJECT_TYPE_DEFINITION] }],
|
1346
|
-
code: (
|
1347
|
-
/* GraphQL */
|
1348
|
-
`
|
1349
|
-
type User {
|
1350
|
-
age: Int
|
1351
|
-
firstName: String!
|
1352
|
-
lastName: String!
|
1353
|
-
password: String
|
1354
|
-
}
|
1355
|
-
`
|
1356
|
-
)
|
1357
|
-
},
|
1358
|
-
{
|
1359
|
-
title: "Incorrect",
|
1360
|
-
usage: [{ values: !0 }],
|
1361
|
-
code: (
|
1362
|
-
/* GraphQL */
|
1363
|
-
`
|
1364
|
-
enum Role {
|
1365
|
-
SUPER_ADMIN
|
1366
|
-
ADMIN # should be before "SUPER_ADMIN"
|
1367
|
-
USER
|
1368
|
-
GOD # should be before "USER"
|
1369
|
-
}
|
1370
|
-
`
|
1371
|
-
)
|
1372
|
-
},
|
1373
|
-
{
|
1374
|
-
title: "Correct",
|
1375
|
-
usage: [{ values: !0 }],
|
1376
|
-
code: (
|
1377
|
-
/* GraphQL */
|
1378
|
-
`
|
1379
|
-
enum Role {
|
1380
|
-
ADMIN
|
1381
|
-
GOD
|
1382
|
-
SUPER_ADMIN
|
1383
|
-
USER
|
1384
|
-
}
|
1385
|
-
`
|
1386
|
-
)
|
1387
|
-
},
|
1388
|
-
{
|
1389
|
-
title: "Incorrect",
|
1390
|
-
usage: [{ selections: [Kind5.OPERATION_DEFINITION] }],
|
1391
|
-
code: (
|
1392
|
-
/* GraphQL */
|
1393
|
-
`
|
1394
|
-
query {
|
1395
|
-
me {
|
1396
|
-
firstName
|
1397
|
-
lastName
|
1398
|
-
email # should be before "lastName"
|
1399
|
-
}
|
1400
|
-
}
|
1401
|
-
`
|
1402
|
-
)
|
1403
|
-
},
|
1404
|
-
{
|
1405
|
-
title: "Correct",
|
1406
|
-
usage: [{ selections: [Kind5.OPERATION_DEFINITION] }],
|
1407
|
-
code: (
|
1408
|
-
/* GraphQL */
|
1409
|
-
`
|
1410
|
-
query {
|
1411
|
-
me {
|
1412
|
-
email
|
1413
|
-
firstName
|
1414
|
-
lastName
|
1415
|
-
}
|
1416
|
-
}
|
1417
|
-
`
|
1418
|
-
)
|
1419
|
-
}
|
1420
|
-
],
|
1421
|
-
configOptions: {
|
1422
|
-
schema: [
|
1423
|
-
{
|
1424
|
-
definitions: !0,
|
1425
|
-
fields: fieldsEnum,
|
1426
|
-
values: !0,
|
1427
|
-
arguments: argumentsEnum,
|
1428
|
-
groups: ["id", "*", "createdAt", "updatedAt"]
|
1429
|
-
}
|
1430
|
-
],
|
1431
|
-
operations: [
|
1432
|
-
{
|
1433
|
-
definitions: !0,
|
1434
|
-
selections: selectionsEnum,
|
1435
|
-
variables: !0,
|
1436
|
-
arguments: [Kind5.FIELD, Kind5.DIRECTIVE],
|
1437
|
-
groups: ["id", "*", "createdAt", "updatedAt"]
|
1438
|
-
}
|
1439
|
-
]
|
1440
|
-
}
|
1643
|
+
description: "A GraphQL document is only valid if all non-repeatable directives at a given location are uniquely named.",
|
1644
|
+
requiresSchema: !0
|
1645
|
+
}
|
1646
|
+
),
|
1647
|
+
validationToRule(
|
1648
|
+
{
|
1649
|
+
ruleId: "unique-field-definition-names",
|
1650
|
+
rule: UniqueFieldDefinitionNamesRule
|
1441
1651
|
},
|
1442
|
-
|
1443
|
-
|
1652
|
+
{
|
1653
|
+
category: "Schema",
|
1654
|
+
description: "A GraphQL complex type is only valid if all its fields are uniquely named."
|
1655
|
+
}
|
1656
|
+
),
|
1657
|
+
validationToRule(
|
1658
|
+
{
|
1659
|
+
ruleId: "unique-input-field-names",
|
1660
|
+
rule: UniqueInputFieldNamesRule
|
1444
1661
|
},
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
let sourceCode = context.getSourceCode();
|
1449
|
-
function isNodeAndCommentOnSameLine(node, comment) {
|
1450
|
-
return node.loc.end.line === comment.loc.start.line;
|
1662
|
+
{
|
1663
|
+
category: "Operations",
|
1664
|
+
description: "A GraphQL input object value is only valid if all supplied fields are uniquely named."
|
1451
1665
|
}
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
let comment = commentsBefore[i];
|
1462
|
-
if (nodeLine - comment.loc.start.line - filteredComments.length > 1)
|
1463
|
-
break;
|
1464
|
-
filteredComments.unshift(comment);
|
1465
|
-
}
|
1466
|
-
return filteredComments;
|
1666
|
+
),
|
1667
|
+
validationToRule(
|
1668
|
+
{
|
1669
|
+
ruleId: "unique-operation-types",
|
1670
|
+
rule: UniqueOperationTypesRule
|
1671
|
+
},
|
1672
|
+
{
|
1673
|
+
category: "Schema",
|
1674
|
+
description: "A GraphQL document is only valid if it has only one type per operation."
|
1467
1675
|
}
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1676
|
+
),
|
1677
|
+
validationToRule(
|
1678
|
+
{
|
1679
|
+
ruleId: "unique-type-names",
|
1680
|
+
rule: UniqueTypeNamesRule
|
1681
|
+
},
|
1682
|
+
{
|
1683
|
+
category: "Schema",
|
1684
|
+
description: "A GraphQL document is only valid if all defined types have unique names."
|
1472
1685
|
}
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
throw new Error("`groups` option should contain `*` string.");
|
1484
|
-
let indexForPrev = groups.indexOf(prevName);
|
1485
|
-
indexForPrev === -1 && (indexForPrev = groups.indexOf("*"));
|
1486
|
-
let indexForCurr = groups.indexOf(currName);
|
1487
|
-
if (indexForCurr === -1 && (indexForCurr = groups.indexOf("*")), shouldSortByGroup = indexForPrev - indexForCurr > 0, indexForPrev < indexForCurr)
|
1488
|
-
continue;
|
1489
|
-
}
|
1490
|
-
if (!shouldSortByGroup && !(compareResult === 1) && (!(compareResult === 0) || !prevNode.kind.endsWith("Extension") || currNode.kind.endsWith("Extension")))
|
1491
|
-
continue;
|
1492
|
-
}
|
1493
|
-
context.report({
|
1494
|
-
// @ts-expect-error can't be undefined
|
1495
|
-
node: "alias" in currNode && currNode.alias || currNode.name,
|
1496
|
-
messageId: RULE_ID,
|
1497
|
-
data: {
|
1498
|
-
currNode: displayNodeName(currNode),
|
1499
|
-
prevNode: prevName ? displayNodeName(prevNode) : lowerCase2(prevNode.kind)
|
1500
|
-
},
|
1501
|
-
*fix(fixer) {
|
1502
|
-
let prevRange = getRangeWithComments(prevNode), currRange = getRangeWithComments(currNode);
|
1503
|
-
yield fixer.replaceTextRange(
|
1504
|
-
prevRange,
|
1505
|
-
sourceCode.getText({ range: currRange })
|
1506
|
-
), yield fixer.replaceTextRange(
|
1507
|
-
currRange,
|
1508
|
-
sourceCode.getText({ range: prevRange })
|
1509
|
-
);
|
1510
|
-
}
|
1511
|
-
});
|
1512
|
-
}
|
1686
|
+
),
|
1687
|
+
validationToRule(
|
1688
|
+
{
|
1689
|
+
ruleId: "unique-variable-names",
|
1690
|
+
rule: UniqueVariableNamesRule
|
1691
|
+
},
|
1692
|
+
{
|
1693
|
+
category: "Operations",
|
1694
|
+
description: "A GraphQL operation is only valid if all its variables are uniquely named.",
|
1695
|
+
requiresSchema: !0
|
1513
1696
|
}
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
Kind5.INPUT_OBJECT_TYPE_EXTENSION
|
1526
|
-
]
|
1527
|
-
].filter(truthy).flat().join(","), selectionsSelector = opts.selections?.join(","), argumentsSelector = opts.arguments?.join(",");
|
1528
|
-
if (fieldsSelector && (listeners[fieldsSelector] = (node) => {
|
1529
|
-
checkNodes(node.fields);
|
1530
|
-
}), opts.values) {
|
1531
|
-
let enumValuesSelector = [Kind5.ENUM_TYPE_DEFINITION, Kind5.ENUM_TYPE_EXTENSION].join(",");
|
1532
|
-
listeners[enumValuesSelector] = (node) => {
|
1533
|
-
checkNodes(node.values);
|
1534
|
-
};
|
1697
|
+
),
|
1698
|
+
validationToRule(
|
1699
|
+
{
|
1700
|
+
ruleId: "value-literals-of-correct-type",
|
1701
|
+
rule: ValuesOfCorrectTypeRule,
|
1702
|
+
hasDidYouMeanSuggestions: !0
|
1703
|
+
},
|
1704
|
+
{
|
1705
|
+
category: "Operations",
|
1706
|
+
description: "A GraphQL document is only valid if all value literals are of the type expected at their position.",
|
1707
|
+
requiresSchema: !0
|
1535
1708
|
}
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1546
|
-
};
|
1547
|
-
|
1548
|
-
// src/rules/description-style.ts
|
1549
|
-
var schema2 = {
|
1550
|
-
type: "array",
|
1551
|
-
maxItems: 1,
|
1552
|
-
items: {
|
1553
|
-
type: "object",
|
1554
|
-
additionalProperties: !1,
|
1555
|
-
minProperties: 1,
|
1556
|
-
properties: {
|
1557
|
-
style: {
|
1558
|
-
enum: ["block", "inline"],
|
1559
|
-
default: "block"
|
1560
|
-
}
|
1709
|
+
),
|
1710
|
+
validationToRule(
|
1711
|
+
{
|
1712
|
+
ruleId: "variables-are-input-types",
|
1713
|
+
rule: VariablesAreInputTypesRule
|
1714
|
+
},
|
1715
|
+
{
|
1716
|
+
category: "Operations",
|
1717
|
+
description: "A GraphQL operation is only valid if all the variables it defines are of input types (scalar, enum, or input object).",
|
1718
|
+
requiresSchema: !0
|
1561
1719
|
}
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1567
|
-
docs: {
|
1568
|
-
examples: [
|
1569
|
-
{
|
1570
|
-
title: "Incorrect",
|
1571
|
-
usage: [{ style: "inline" }],
|
1572
|
-
code: (
|
1573
|
-
/* GraphQL */
|
1574
|
-
`
|
1575
|
-
""" Description """
|
1576
|
-
type someTypeName {
|
1577
|
-
# ...
|
1578
|
-
}
|
1579
|
-
`
|
1580
|
-
)
|
1581
|
-
},
|
1582
|
-
{
|
1583
|
-
title: "Correct",
|
1584
|
-
usage: [{ style: "inline" }],
|
1585
|
-
code: (
|
1586
|
-
/* GraphQL */
|
1587
|
-
`
|
1588
|
-
" Description "
|
1589
|
-
type someTypeName {
|
1590
|
-
# ...
|
1591
|
-
}
|
1592
|
-
`
|
1593
|
-
)
|
1594
|
-
}
|
1595
|
-
],
|
1596
|
-
description: "Require all comments to follow the same style (either block or inline).",
|
1597
|
-
category: "Schema",
|
1598
|
-
url: "https://the-guild.dev/graphql/eslint/rules/description-style",
|
1599
|
-
recommended: !0
|
1720
|
+
),
|
1721
|
+
validationToRule(
|
1722
|
+
{
|
1723
|
+
ruleId: "variables-in-allowed-position",
|
1724
|
+
rule: VariablesInAllowedPositionRule
|
1600
1725
|
},
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
loc: isBlock ? node.loc : node.loc.start,
|
1609
|
-
message: `Unexpected ${isBlock ? "inline" : "block"} description for ${getNodeName(
|
1610
|
-
node.parent
|
1611
|
-
)}`,
|
1612
|
-
suggest: [
|
1613
|
-
{
|
1614
|
-
desc: `Change to ${isBlock ? "block" : "inline"} style description`,
|
1615
|
-
fix(fixer) {
|
1616
|
-
let originalText = context.getSourceCode().getText(node), newText = isBlock ? originalText.replace(/(^")|("$)/g, '"""') : originalText.replace(/(^""")|("""$)/g, '"').replace(/\s+/g, " ");
|
1617
|
-
return fixer.replaceText(node, newText);
|
1618
|
-
}
|
1619
|
-
}
|
1620
|
-
]
|
1621
|
-
});
|
1622
|
-
}
|
1623
|
-
};
|
1624
|
-
}
|
1625
|
-
};
|
1726
|
+
{
|
1727
|
+
category: "Operations",
|
1728
|
+
description: "Variables passed to field arguments conform to type.",
|
1729
|
+
requiresSchema: !0
|
1730
|
+
}
|
1731
|
+
)
|
1732
|
+
);
|
1626
1733
|
|
1627
1734
|
// src/rules/input-name.ts
|
1628
1735
|
import {
|
@@ -1742,10 +1849,10 @@ Using the same name for all input parameters will make your schemas easier to co
|
|
1742
1849
|
return currentNode;
|
1743
1850
|
})(node);
|
1744
1851
|
if (shouldCheckType(inputValueNode.parent.parent)) {
|
1745
|
-
let mutationName = `${inputValueNode.parent.name.value}Input`,
|
1746
|
-
(options.caseSensitiveInputType && node.name.value !== mutationName ||
|
1852
|
+
let mutationName = `${inputValueNode.parent.name.value}Input`, name2 = node.name.value;
|
1853
|
+
(options.caseSensitiveInputType && node.name.value !== mutationName || name2.toLowerCase() !== mutationName.toLowerCase()) && context.report({
|
1747
1854
|
node: node.name,
|
1748
|
-
message: `Input type \`${
|
1855
|
+
message: `Input type \`${name2}\` name should be \`${mutationName}\`.`,
|
1749
1856
|
suggest: [
|
1750
1857
|
{
|
1751
1858
|
desc: `Rename to \`${mutationName}\``,
|
@@ -1828,11 +1935,11 @@ var RULE_ID2 = "lone-executable-definition", definitionTypes = ["fragment", ...O
|
|
1828
1935
|
},
|
1829
1936
|
"Document:exit"() {
|
1830
1937
|
for (let { node, type } of definitions.slice(1)) {
|
1831
|
-
let
|
1832
|
-
definitionName && (
|
1938
|
+
let name2 = pascalCase(type), definitionName = node.name?.value;
|
1939
|
+
definitionName && (name2 += ` "${definitionName}"`), context.report({
|
1833
1940
|
loc: node.name?.loc || getLocation(node.loc.start, type),
|
1834
1941
|
messageId: RULE_ID2,
|
1835
|
-
data: { name }
|
1942
|
+
data: { name: name2 }
|
1836
1943
|
});
|
1837
1944
|
}
|
1838
1945
|
}
|
@@ -2399,51 +2506,51 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(`
|
|
2399
2506
|
report(node, `${nodeType} "${nodeName}" should ${errorMessage}`, suggestedNames);
|
2400
2507
|
}
|
2401
2508
|
function getError() {
|
2402
|
-
let
|
2403
|
-
if (ignorePattern && new RegExp(ignorePattern, "u").test(
|
2509
|
+
let name2 = nodeName.replace(/(^_+)|(_+$)/g, "");
|
2510
|
+
if (ignorePattern && new RegExp(ignorePattern, "u").test(name2))
|
2404
2511
|
return;
|
2405
|
-
if (prefix && !
|
2512
|
+
if (prefix && !name2.startsWith(prefix))
|
2406
2513
|
return {
|
2407
2514
|
errorMessage: `have "${prefix}" prefix`,
|
2408
|
-
renameToNames: [prefix +
|
2515
|
+
renameToNames: [prefix + name2]
|
2409
2516
|
};
|
2410
|
-
if (suffix && !
|
2517
|
+
if (suffix && !name2.endsWith(suffix))
|
2411
2518
|
return {
|
2412
2519
|
errorMessage: `have "${suffix}" suffix`,
|
2413
|
-
renameToNames: [
|
2520
|
+
renameToNames: [name2 + suffix]
|
2414
2521
|
};
|
2415
|
-
let forbiddenPrefix = forbiddenPrefixes?.find((prefix2) =>
|
2522
|
+
let forbiddenPrefix = forbiddenPrefixes?.find((prefix2) => name2.startsWith(prefix2));
|
2416
2523
|
if (forbiddenPrefix)
|
2417
2524
|
return {
|
2418
2525
|
errorMessage: `not have "${forbiddenPrefix}" prefix`,
|
2419
|
-
renameToNames: [
|
2526
|
+
renameToNames: [name2.replace(new RegExp(`^${forbiddenPrefix}`), "")]
|
2420
2527
|
};
|
2421
|
-
let forbiddenSuffix = forbiddenSuffixes?.find((suffix2) =>
|
2528
|
+
let forbiddenSuffix = forbiddenSuffixes?.find((suffix2) => name2.endsWith(suffix2));
|
2422
2529
|
if (forbiddenSuffix)
|
2423
2530
|
return {
|
2424
2531
|
errorMessage: `not have "${forbiddenSuffix}" suffix`,
|
2425
|
-
renameToNames: [
|
2532
|
+
renameToNames: [name2.replace(new RegExp(`${forbiddenSuffix}$`), "")]
|
2426
2533
|
};
|
2427
|
-
if (requiredPrefixes && !requiredPrefixes.some((requiredPrefix) =>
|
2534
|
+
if (requiredPrefixes && !requiredPrefixes.some((requiredPrefix) => name2.startsWith(requiredPrefix)))
|
2428
2535
|
return {
|
2429
2536
|
errorMessage: `have one of the following prefixes: ${englishJoinWords(
|
2430
2537
|
requiredPrefixes
|
2431
2538
|
)}`,
|
2432
|
-
renameToNames: style ? requiredPrefixes.map((prefix2) => convertCase(style, `${prefix2} ${
|
2539
|
+
renameToNames: style ? requiredPrefixes.map((prefix2) => convertCase(style, `${prefix2} ${name2}`)) : requiredPrefixes.map((prefix2) => `${prefix2}${name2}`)
|
2433
2540
|
};
|
2434
|
-
if (requiredSuffixes && !requiredSuffixes.some((requiredSuffix) =>
|
2541
|
+
if (requiredSuffixes && !requiredSuffixes.some((requiredSuffix) => name2.endsWith(requiredSuffix)))
|
2435
2542
|
return {
|
2436
2543
|
errorMessage: `have one of the following suffixes: ${englishJoinWords(
|
2437
2544
|
requiredSuffixes
|
2438
2545
|
)}`,
|
2439
|
-
renameToNames: style ? requiredSuffixes.map((suffix2) => convertCase(style, `${
|
2546
|
+
renameToNames: style ? requiredSuffixes.map((suffix2) => convertCase(style, `${name2} ${suffix2}`)) : requiredSuffixes.map((suffix2) => `${name2}${suffix2}`)
|
2440
2547
|
};
|
2441
2548
|
if (!style)
|
2442
2549
|
return;
|
2443
|
-
if (!StyleToRegex[style].test(
|
2550
|
+
if (!StyleToRegex[style].test(name2))
|
2444
2551
|
return {
|
2445
2552
|
errorMessage: `be in ${style} format`,
|
2446
|
-
renameToNames: [convertCase(style,
|
2553
|
+
renameToNames: [convertCase(style, name2)]
|
2447
2554
|
};
|
2448
2555
|
}
|
2449
2556
|
}, checkUnderscore = (isLeading) => (node) => {
|
@@ -2930,8 +3037,8 @@ var RULE_ID7 = "no-one-place-fragments", rule11 = {
|
|
2930
3037
|
for (let { document, filePath } of allDocuments) {
|
2931
3038
|
let relativeFilePath = relative(CWD, filePath);
|
2932
3039
|
visit4(document, {
|
2933
|
-
FragmentSpread({ name }) {
|
2934
|
-
let spreadName =
|
3040
|
+
FragmentSpread({ name: name2 }) {
|
3041
|
+
let spreadName = name2.value;
|
2935
3042
|
usedFragmentsMap[spreadName] ||= [], usedFragmentsMap[spreadName].push(relativeFilePath);
|
2936
3043
|
}
|
2937
3044
|
});
|
@@ -3186,7 +3293,7 @@ var RULE_ID9 = "no-unreachable-types", KINDS = [
|
|
3186
3293
|
Kind13.UNION_TYPE_EXTENSION,
|
3187
3294
|
Kind13.ENUM_TYPE_DEFINITION,
|
3188
3295
|
Kind13.ENUM_TYPE_EXTENSION
|
3189
|
-
], reachableTypesCache, RequestDirectiveLocations = /* @__PURE__ */ new Set([
|
3296
|
+
], reachableTypesCache = new ModuleCache(), RequestDirectiveLocations = /* @__PURE__ */ new Set([
|
3190
3297
|
DirectiveLocation.QUERY,
|
3191
3298
|
DirectiveLocation.MUTATION,
|
3192
3299
|
DirectiveLocation.SUBSCRIPTION,
|
@@ -3197,8 +3304,9 @@ var RULE_ID9 = "no-unreachable-types", KINDS = [
|
|
3197
3304
|
DirectiveLocation.VARIABLE_DEFINITION
|
3198
3305
|
]);
|
3199
3306
|
function getReachableTypes(schema15) {
|
3200
|
-
|
3201
|
-
|
3307
|
+
let cachedValue = reachableTypesCache.get(schema15);
|
3308
|
+
if (cachedValue)
|
3309
|
+
return cachedValue;
|
3202
3310
|
let reachableTypes = /* @__PURE__ */ new Set(), collect = (node) => {
|
3203
3311
|
let typeName = getTypeName(node);
|
3204
3312
|
if (reachableTypes.has(typeName))
|
@@ -3209,8 +3317,7 @@ function getReachableTypes(schema15) {
|
|
3209
3317
|
let { objects, interfaces } = schema15.getImplementations(type);
|
3210
3318
|
for (let { astNode } of [...objects, ...interfaces])
|
3211
3319
|
visit5(astNode, visitor);
|
3212
|
-
} else
|
3213
|
-
type?.astNode && visit5(type.astNode, visitor);
|
3320
|
+
} else type?.astNode && visit5(type.astNode, visitor);
|
3214
3321
|
}, visitor = {
|
3215
3322
|
InterfaceTypeDefinition: collect,
|
3216
3323
|
ObjectTypeDefinition: collect,
|
@@ -3236,7 +3343,7 @@ function getReachableTypes(schema15) {
|
|
3236
3343
|
argTypeName && reachableTypes.add(argTypeName);
|
3237
3344
|
}
|
3238
3345
|
}
|
3239
|
-
return reachableTypesCache
|
3346
|
+
return reachableTypesCache.set(schema15, reachableTypes), reachableTypes;
|
3240
3347
|
}
|
3241
3348
|
var rule15 = {
|
3242
3349
|
meta: {
|
@@ -3317,10 +3424,11 @@ var rule15 = {
|
|
3317
3424
|
|
3318
3425
|
// src/rules/no-unused-fields.ts
|
3319
3426
|
import { TypeInfo as TypeInfo2, visit as visit6, visitWithTypeInfo as visitWithTypeInfo2 } from "graphql";
|
3320
|
-
var RULE_ID10 = "no-unused-fields", usedFieldsCache;
|
3427
|
+
var RULE_ID10 = "no-unused-fields", usedFieldsCache = new ModuleCache();
|
3321
3428
|
function getUsedFields(schema15, operations) {
|
3322
|
-
|
3323
|
-
|
3429
|
+
let cachedValue = usedFieldsCache.get(schema15);
|
3430
|
+
if (cachedValue)
|
3431
|
+
return cachedValue;
|
3324
3432
|
let usedFields = /* @__PURE__ */ Object.create(null), typeInfo = new TypeInfo2(schema15), visitor = visitWithTypeInfo2(typeInfo, {
|
3325
3433
|
Field(node) {
|
3326
3434
|
if (!typeInfo.getFieldDef())
|
@@ -3331,7 +3439,7 @@ function getUsedFields(schema15, operations) {
|
|
3331
3439
|
}), allDocuments = [...operations.getOperations(), ...operations.getFragments()];
|
3332
3440
|
for (let { document } of allDocuments)
|
3333
3441
|
visit6(document, visitor);
|
3334
|
-
return usedFieldsCache
|
3442
|
+
return usedFieldsCache.set(schema15, usedFields), usedFields;
|
3335
3443
|
}
|
3336
3444
|
var rule16 = {
|
3337
3445
|
meta: {
|
@@ -3615,13 +3723,13 @@ var MUST_BE_OBJECT_TYPE = "MUST_BE_OBJECT_TYPE", MUST_CONTAIN_FIELD_EDGES = "MUS
|
|
3615
3723
|
};
|
3616
3724
|
|
3617
3725
|
// src/rules/relay-edge-types.ts
|
3618
|
-
import { getDocumentNodeFromSchema } from "@graphql-tools/utils";
|
3619
3726
|
import {
|
3620
3727
|
isObjectType as isObjectType2,
|
3621
3728
|
isScalarType as isScalarType3,
|
3622
3729
|
Kind as Kind16,
|
3623
3730
|
visit as visit7
|
3624
3731
|
} from "graphql";
|
3732
|
+
import { getDocumentNodeFromSchema } from "@graphql-tools/utils";
|
3625
3733
|
var RULE_ID12 = "relay-edge-types", MESSAGE_MUST_BE_OBJECT_TYPE = "MESSAGE_MUST_BE_OBJECT_TYPE", MESSAGE_MISSING_EDGE_SUFFIX = "MESSAGE_MISSING_EDGE_SUFFIX", MESSAGE_LIST_TYPE_ONLY_EDGE_TYPE = "MESSAGE_LIST_TYPE_ONLY_EDGE_TYPE", MESSAGE_SHOULD_IMPLEMENTS_NODE = "MESSAGE_SHOULD_IMPLEMENTS_NODE", edgeTypesCache;
|
3626
3734
|
function getEdgeTypes(schema15) {
|
3627
3735
|
if (edgeTypesCache)
|
@@ -4019,8 +4127,8 @@ var rule22 = {
|
|
4019
4127
|
};
|
4020
4128
|
|
4021
4129
|
// src/rules/require-description.ts
|
4022
|
-
import { getRootTypeNames } from "@graphql-tools/utils";
|
4023
4130
|
import { Kind as Kind18, TokenKind as TokenKind3 } from "graphql";
|
4131
|
+
import { getRootTypeNames } from "@graphql-tools/utils";
|
4024
4132
|
var RULE_ID14 = "require-description", ALLOWED_KINDS2 = [
|
4025
4133
|
...TYPES_KINDS,
|
4026
4134
|
Kind18.DIRECTIVE_DEFINITION,
|
@@ -4321,21 +4429,17 @@ var RULE_ID16 = "require-import-fragment", SUGGESTION_ID = "add-import-expressio
|
|
4321
4429
|
for (let comment of comments) {
|
4322
4430
|
if (comment.type !== "Line" || !new RegExp(
|
4323
4431
|
`^\\s*import\\s+(${fragmentName}\\s+from\\s+)?['"]`
|
4324
|
-
).test(comment.value))
|
4325
|
-
continue;
|
4432
|
+
).test(comment.value)) continue;
|
4326
4433
|
let extractedImportPath = comment.value.match(/(["'])((?:\1|.)*?)\1/)?.[2];
|
4327
|
-
if (!extractedImportPath)
|
4328
|
-
continue;
|
4434
|
+
if (!extractedImportPath) continue;
|
4329
4435
|
let importPath = path.join(path.dirname(filePath), extractedImportPath);
|
4330
4436
|
if (fragmentsFromSiblings.some(
|
4331
4437
|
(source) => source.filePath === importPath
|
4332
|
-
))
|
4333
|
-
return;
|
4438
|
+
)) return;
|
4334
4439
|
}
|
4335
4440
|
if (fragmentsFromSiblings.some(
|
4336
4441
|
(source) => source.filePath === filePath
|
4337
|
-
))
|
4338
|
-
return;
|
4442
|
+
)) return;
|
4339
4443
|
let suggestedFilePaths = fragmentsFromSiblings.length ? fragmentsFromSiblings.map((o) => path.relative(path.dirname(filePath), o.filePath)) : ["CHANGE_ME.graphql"];
|
4340
4444
|
context.report({
|
4341
4445
|
node,
|
@@ -4468,7 +4572,7 @@ var RULE_ID18 = "require-nullable-result-in-root", rule27 = {
|
|
4468
4572
|
for (let field of node.fields || []) {
|
4469
4573
|
if (field.gqlType.type !== Kind20.NON_NULL_TYPE || field.gqlType.gqlType.type !== Kind20.NAMED_TYPE)
|
4470
4574
|
continue;
|
4471
|
-
let
|
4575
|
+
let name2 = field.gqlType.gqlType.name.value, type = schema15.getType(name2), resultType = type?.astNode ? getNodeName(type.astNode) : type?.name;
|
4472
4576
|
context.report({
|
4473
4577
|
node: field.gqlType,
|
4474
4578
|
messageId: RULE_ID18,
|
@@ -4493,7 +4597,6 @@ var RULE_ID18 = "require-nullable-result-in-root", rule27 = {
|
|
4493
4597
|
};
|
4494
4598
|
|
4495
4599
|
// src/rules/require-selections.ts
|
4496
|
-
import { asArray } from "@graphql-tools/utils";
|
4497
4600
|
import {
|
4498
4601
|
GraphQLInterfaceType,
|
4499
4602
|
GraphQLObjectType,
|
@@ -4503,6 +4606,7 @@ import {
|
|
4503
4606
|
visit as visit8,
|
4504
4607
|
visitWithTypeInfo as visitWithTypeInfo3
|
4505
4608
|
} from "graphql";
|
4609
|
+
import { asArray } from "@graphql-tools/utils";
|
4506
4610
|
var RULE_ID19 = "require-selections", DEFAULT_ID_FIELD_NAME = "id", schema12 = {
|
4507
4611
|
definitions: {
|
4508
4612
|
asString: {
|
@@ -4525,6 +4629,7 @@ var RULE_ID19 = "require-selections", DEFAULT_ID_FIELD_NAME = "id", schema12 = {
|
|
4525
4629
|
}, rule28 = {
|
4526
4630
|
meta: {
|
4527
4631
|
type: "suggestion",
|
4632
|
+
// eslint-disable-next-line eslint-plugin/require-meta-has-suggestions -- false positive since we assign `problem.suggest` conditionally
|
4528
4633
|
hasSuggestions: !0,
|
4529
4634
|
docs: {
|
4530
4635
|
category: "Operations",
|
@@ -4627,7 +4732,7 @@ Include it in your selection set{{ addition }}.`
|
|
4627
4732
|
}
|
4628
4733
|
function checkFields(rawType2) {
|
4629
4734
|
let fields = rawType2.getFields();
|
4630
|
-
if (!idNames.some((
|
4735
|
+
if (!idNames.some((name2) => fields[name2]))
|
4631
4736
|
return;
|
4632
4737
|
function hasIdField({ selections }) {
|
4633
4738
|
return selections.some((selection) => {
|
@@ -4649,8 +4754,8 @@ Include it in your selection set{{ addition }}.`
|
|
4649
4754
|
if (checkFragments(node), hasId)
|
4650
4755
|
return;
|
4651
4756
|
let pluralSuffix = idNames.length > 1 ? "s" : "", fieldName2 = englishJoinWords(
|
4652
|
-
idNames.map((
|
4653
|
-
), addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${englishJoinWords([...checkedFragmentSpreads].map((
|
4757
|
+
idNames.map((name2) => `\`${(parent.alias || parent.name).value}.${name2}\``)
|
4758
|
+
), addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${englishJoinWords([...checkedFragmentSpreads].map((name2) => `\`${name2}\``))}`, problem = {
|
4654
4759
|
loc,
|
4655
4760
|
messageId: RULE_ID19,
|
4656
4761
|
data: {
|
@@ -4830,7 +4935,7 @@ var RULE_ID21 = "selection-set-depth", schema13 = {
|
|
4830
4935
|
checkFn({
|
4831
4936
|
getDocument: () => document,
|
4832
4937
|
reportError(error) {
|
4833
|
-
let { line, column } = error.locations[0], token = context.getAncestors()[0].tokens.find(
|
4938
|
+
let { line, column } = error.locations[0], token = context.sourceCode.getAncestors(node)[0].tokens.find(
|
4834
4939
|
(token2) => token2.loc.start.line === line && token2.loc.start.column === column - 1
|
4835
4940
|
);
|
4836
4941
|
context.report({
|
@@ -5274,7 +5379,7 @@ var rules = {
|
|
5274
5379
|
};
|
5275
5380
|
|
5276
5381
|
// src/configs/index.ts
|
5277
|
-
var import_operations_all = __toESM(require_operations_all()), import_operations_recommended = __toESM(require_operations_recommended()), import_schema_all = __toESM(require_schema_all()), import_schema_recommended = __toESM(require_schema_recommended()), import_schema_relay = __toESM(require_schema_relay()), configs = {
|
5382
|
+
var import_operations_all = __toESM(require_operations_all(), 1), import_operations_recommended = __toESM(require_operations_recommended(), 1), import_schema_all = __toESM(require_schema_all(), 1), import_schema_recommended = __toESM(require_schema_recommended(), 1), import_schema_relay = __toESM(require_schema_relay(), 1), configs = {
|
5278
5383
|
"schema-recommended": import_schema_recommended.default,
|
5279
5384
|
"schema-all": import_schema_all.default,
|
5280
5385
|
"schema-relay": import_schema_relay.default,
|
@@ -5283,9 +5388,7 @@ var import_operations_all = __toESM(require_operations_all()), import_operations
|
|
5283
5388
|
};
|
5284
5389
|
|
5285
5390
|
// src/flat-configs.ts
|
5286
|
-
var languageOptions = {
|
5287
|
-
parser: { parseForESLint }
|
5288
|
-
}, flatConfigs = {
|
5391
|
+
var languageOptions = { parser }, flatConfigs = {
|
5289
5392
|
"operations-all": {
|
5290
5393
|
languageOptions,
|
5291
5394
|
rules: {
|
@@ -5314,10 +5417,7 @@ var languageOptions = {
|
|
5314
5417
|
}
|
5315
5418
|
};
|
5316
5419
|
export {
|
5317
|
-
configs,
|
5318
5420
|
flatConfigs,
|
5319
|
-
|
5320
|
-
requireGraphQLSchemaFromContext,
|
5321
|
-
requireSiblingsOperations,
|
5421
|
+
parser,
|
5322
5422
|
rules
|
5323
5423
|
};
|