@graphql-eslint/eslint-plugin 4.0.0-alpha.0 → 4.0.0-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +0 -2
- package/cjs/documents.d.ts +1 -1
- package/cjs/estree-converter/types.d.ts +1 -1
- package/cjs/flat-configs.d.ts +2 -2
- package/cjs/graphql-config.d.ts +1 -1
- package/cjs/graphql-config.js +1 -1
- package/cjs/index.d.ts +2 -3
- package/cjs/parser.d.ts +2 -2
- package/cjs/parser.js +2 -2
- package/cjs/processor.d.ts +1 -1
- package/cjs/rules/alphabetize.d.ts +4 -4
- package/cjs/rules/description-style.d.ts +3 -3
- package/cjs/rules/graphql-js-validation.d.ts +2 -2
- package/cjs/rules/index.d.ts +9 -10
- package/cjs/rules/index.js +1 -1
- package/cjs/rules/input-name.d.ts +3 -3
- package/cjs/rules/lone-executable-definition.d.ts +3 -3
- package/cjs/rules/match-document-filename.d.ts +3 -3
- package/cjs/rules/naming-convention.d.ts +3 -3
- package/cjs/rules/no-anonymous-operations.d.ts +2 -2
- package/cjs/rules/no-deprecated.d.ts +2 -2
- package/cjs/rules/no-duplicate-fields.d.ts +2 -2
- package/cjs/rules/no-hashtag-description.d.ts +2 -2
- package/cjs/rules/no-one-place-fragments.d.ts +2 -2
- package/cjs/rules/no-root-type.d.ts +3 -3
- package/cjs/rules/no-scalar-result-type-on-mutation.d.ts +2 -2
- package/cjs/rules/no-typename-prefix.d.ts +2 -2
- package/cjs/rules/no-unreachable-types.d.ts +2 -2
- package/cjs/rules/no-unreachable-types.js +1 -2
- package/cjs/rules/no-unused-fields.d.ts +2 -2
- package/cjs/rules/relay-arguments.d.ts +3 -3
- package/cjs/rules/relay-connection-types.d.ts +2 -2
- package/cjs/rules/relay-edge-types.d.ts +3 -3
- package/cjs/rules/relay-edge-types.js +1 -1
- package/cjs/rules/relay-page-info.d.ts +2 -2
- package/cjs/rules/require-deprecation-date.d.ts +3 -3
- package/cjs/rules/require-deprecation-reason.d.ts +2 -2
- package/cjs/rules/require-description.d.ts +3 -3
- package/cjs/rules/require-description.js +1 -1
- package/cjs/rules/require-field-of-type-query-in-mutation-result.d.ts +2 -2
- package/cjs/rules/require-import-fragment.d.ts +2 -2
- package/cjs/rules/require-import-fragment.js +4 -8
- package/cjs/rules/require-nullable-fields-with-oneof.d.ts +2 -2
- package/cjs/rules/require-nullable-result-in-root.d.ts +2 -2
- package/cjs/rules/require-selections.d.ts +3 -3
- package/cjs/rules/require-selections.js +1 -1
- package/cjs/rules/require-type-pattern-with-oneof.d.ts +2 -2
- package/cjs/rules/selection-set-depth.d.ts +3 -3
- package/cjs/rules/strict-id-in-types.d.ts +3 -3
- package/cjs/rules/unique-enum-value-names.d.ts +2 -2
- package/cjs/rules/unique-fragment-name.d.ts +1 -1
- package/cjs/rules/unique-operation-name.d.ts +2 -2
- package/cjs/schema.d.ts +1 -1
- package/cjs/siblings.d.ts +2 -2
- package/cjs/types.d.ts +4 -3
- package/cjs/utils.d.ts +3 -3
- package/esm/cache.js +1 -1
- 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.d.mts +1 -1
- package/esm/documents.js +1 -1
- package/esm/estree-converter/converter.js +1 -1
- package/esm/estree-converter/types.d.mts +1 -1
- package/esm/estree-converter/utils.js +1 -1
- package/esm/flat-configs.d.mts +2 -2
- package/esm/flat-configs.js +1 -1
- package/esm/graphql-config.d.mts +1 -1
- package/esm/graphql-config.js +2 -2
- package/esm/index.d.mts +2 -3
- package/esm/index.js +1 -1
- package/esm/parser.d.mts +2 -2
- package/esm/parser.js +3 -3
- package/esm/processor.d.mts +1 -1
- package/esm/processor.js +1 -1
- package/esm/rules/alphabetize.d.mts +3 -3
- package/esm/rules/alphabetize.js +1 -1
- package/esm/rules/description-style.d.mts +3 -3
- package/esm/rules/description-style.js +1 -1
- package/esm/rules/graphql-js-validation.d.mts +2 -2
- package/esm/rules/graphql-js-validation.js +1 -1
- package/esm/rules/index.d.mts +4 -5
- package/esm/rules/index.js +2 -2
- package/esm/rules/input-name.d.mts +3 -3
- package/esm/rules/input-name.js +1 -1
- package/esm/rules/lone-executable-definition.d.mts +3 -3
- package/esm/rules/lone-executable-definition.js +1 -1
- package/esm/rules/match-document-filename.d.mts +3 -3
- package/esm/rules/match-document-filename.js +1 -1
- package/esm/rules/naming-convention.d.mts +3 -3
- package/esm/rules/naming-convention.js +1 -1
- package/esm/rules/no-anonymous-operations.d.mts +2 -2
- package/esm/rules/no-anonymous-operations.js +1 -1
- package/esm/rules/no-deprecated.d.mts +2 -2
- package/esm/rules/no-deprecated.js +1 -1
- package/esm/rules/no-duplicate-fields.d.mts +2 -2
- package/esm/rules/no-duplicate-fields.js +1 -1
- package/esm/rules/no-hashtag-description.d.mts +2 -2
- package/esm/rules/no-hashtag-description.js +1 -1
- package/esm/rules/no-one-place-fragments.d.mts +2 -2
- package/esm/rules/no-one-place-fragments.js +1 -1
- package/esm/rules/no-root-type.d.mts +3 -3
- package/esm/rules/no-root-type.js +1 -1
- package/esm/rules/no-scalar-result-type-on-mutation.d.mts +2 -2
- package/esm/rules/no-scalar-result-type-on-mutation.js +1 -1
- package/esm/rules/no-typename-prefix.d.mts +2 -2
- package/esm/rules/no-typename-prefix.js +1 -1
- package/esm/rules/no-unreachable-types.d.mts +2 -2
- package/esm/rules/no-unreachable-types.js +2 -3
- package/esm/rules/no-unused-fields.d.mts +2 -2
- package/esm/rules/no-unused-fields.js +1 -1
- package/esm/rules/relay-arguments.d.mts +3 -3
- package/esm/rules/relay-arguments.js +1 -1
- package/esm/rules/relay-connection-types.d.mts +2 -2
- package/esm/rules/relay-connection-types.js +1 -1
- package/esm/rules/relay-edge-types.d.mts +3 -3
- package/esm/rules/relay-edge-types.js +2 -2
- package/esm/rules/relay-page-info.d.mts +2 -2
- package/esm/rules/relay-page-info.js +1 -1
- package/esm/rules/require-deprecation-date.d.mts +3 -3
- package/esm/rules/require-deprecation-date.js +1 -1
- package/esm/rules/require-deprecation-reason.d.mts +2 -2
- package/esm/rules/require-deprecation-reason.js +1 -1
- package/esm/rules/require-description.d.mts +3 -3
- package/esm/rules/require-description.js +2 -2
- package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +2 -2
- package/esm/rules/require-field-of-type-query-in-mutation-result.js +1 -1
- package/esm/rules/require-import-fragment.d.mts +2 -2
- package/esm/rules/require-import-fragment.js +5 -9
- package/esm/rules/require-nullable-fields-with-oneof.d.mts +2 -2
- package/esm/rules/require-nullable-fields-with-oneof.js +1 -1
- package/esm/rules/require-nullable-result-in-root.d.mts +2 -2
- package/esm/rules/require-nullable-result-in-root.js +1 -1
- package/esm/rules/require-selections.d.mts +3 -3
- package/esm/rules/require-selections.js +2 -2
- package/esm/rules/require-type-pattern-with-oneof.d.mts +2 -2
- package/esm/rules/require-type-pattern-with-oneof.js +1 -1
- package/esm/rules/selection-set-depth.d.mts +3 -3
- package/esm/rules/selection-set-depth.js +1 -1
- package/esm/rules/strict-id-in-types.d.mts +3 -3
- package/esm/rules/strict-id-in-types.js +1 -1
- package/esm/rules/unique-enum-value-names.d.mts +2 -2
- package/esm/rules/unique-enum-value-names.js +1 -1
- package/esm/rules/unique-fragment-name.d.mts +1 -1
- package/esm/rules/unique-fragment-name.js +1 -1
- package/esm/rules/unique-operation-name.d.mts +2 -2
- package/esm/rules/unique-operation-name.js +1 -1
- package/esm/schema.d.mts +1 -1
- package/esm/schema.js +1 -1
- package/esm/siblings.d.mts +2 -2
- package/esm/siblings.js +1 -1
- package/esm/types.d.mts +4 -3
- package/esm/utils.d.mts +3 -3
- package/esm/utils.js +1 -1
- package/index.browser.mjs +721 -726
- package/package.json +5 -5
- /package/esm/{chunk-U3TKCM4X.js → chunk-UIAXBAMD.js} +0 -0
package/index.browser.mjs
CHANGED
@@ -237,9 +237,9 @@ var require_schema_relay = __commonJS({
|
|
237
237
|
});
|
238
238
|
|
239
239
|
// src/parser.ts
|
240
|
-
import { parseGraphQLSDL } from "@graphql-tools/utils";
|
241
240
|
import debugFactory from "debug";
|
242
241
|
import { buildSchema, GraphQLError } from "graphql";
|
242
|
+
import { parseGraphQLSDL } from "@graphql-tools/utils";
|
243
243
|
|
244
244
|
// src/estree-converter/converter.ts
|
245
245
|
import {
|
@@ -641,212 +641,586 @@ function parseForESLint(code, options) {
|
|
641
641
|
}
|
642
642
|
}
|
643
643
|
|
644
|
-
// src/rules/
|
644
|
+
// src/rules/alphabetize.ts
|
645
645
|
import {
|
646
|
-
Kind as Kind4
|
647
|
-
validate,
|
648
|
-
visit as visit3
|
646
|
+
Kind as Kind4
|
649
647
|
} 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.`
|
648
|
+
import lowerCase2 from "lodash.lowercase";
|
649
|
+
var RULE_ID = "alphabetize", fieldsEnum = [
|
650
|
+
Kind4.OBJECT_TYPE_DEFINITION,
|
651
|
+
Kind4.INTERFACE_TYPE_DEFINITION,
|
652
|
+
Kind4.INPUT_OBJECT_TYPE_DEFINITION
|
653
|
+
], selectionsEnum = [
|
654
|
+
Kind4.OPERATION_DEFINITION,
|
655
|
+
Kind4.FRAGMENT_DEFINITION
|
656
|
+
], argumentsEnum = [
|
657
|
+
Kind4.FIELD_DEFINITION,
|
658
|
+
Kind4.FIELD,
|
659
|
+
Kind4.DIRECTIVE_DEFINITION,
|
660
|
+
Kind4.DIRECTIVE
|
661
|
+
], schema = {
|
662
|
+
type: "array",
|
663
|
+
minItems: 1,
|
664
|
+
maxItems: 1,
|
665
|
+
items: {
|
666
|
+
type: "object",
|
667
|
+
additionalProperties: !1,
|
668
|
+
minProperties: 1,
|
669
|
+
properties: {
|
670
|
+
fields: {
|
671
|
+
...ARRAY_DEFAULT_OPTIONS,
|
672
|
+
items: {
|
673
|
+
enum: fieldsEnum
|
674
|
+
},
|
675
|
+
description: "Fields of `type`, `interface`, and `input`."
|
770
676
|
},
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
677
|
+
values: {
|
678
|
+
type: "boolean",
|
679
|
+
description: "Values of `enum`."
|
680
|
+
},
|
681
|
+
selections: {
|
682
|
+
...ARRAY_DEFAULT_OPTIONS,
|
683
|
+
items: {
|
684
|
+
enum: selectionsEnum
|
685
|
+
},
|
686
|
+
description: "Selections of `fragment` and operations `query`, `mutation` and `subscription`."
|
687
|
+
},
|
688
|
+
variables: {
|
689
|
+
type: "boolean",
|
690
|
+
description: "Variables of operations `query`, `mutation` and `subscription`."
|
691
|
+
},
|
692
|
+
arguments: {
|
693
|
+
...ARRAY_DEFAULT_OPTIONS,
|
694
|
+
items: {
|
695
|
+
enum: argumentsEnum
|
696
|
+
},
|
697
|
+
description: "Arguments of fields and directives."
|
698
|
+
},
|
699
|
+
definitions: {
|
700
|
+
type: "boolean",
|
701
|
+
description: "Definitions \u2013 `type`, `interface`, `enum`, `scalar`, `input`, `union` and `directive`."
|
702
|
+
},
|
703
|
+
groups: {
|
704
|
+
...ARRAY_DEFAULT_OPTIONS,
|
705
|
+
minItems: 2,
|
706
|
+
description: "Custom order group. Example: `['id', '*', 'createdAt', 'updatedAt']` where `*` says for everything else."
|
707
|
+
}
|
787
708
|
}
|
788
709
|
}
|
789
|
-
}
|
790
|
-
{
|
791
|
-
|
792
|
-
|
793
|
-
|
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
|
-
{
|
710
|
+
}, rule = {
|
711
|
+
meta: {
|
712
|
+
type: "suggestion",
|
713
|
+
fixable: "code",
|
714
|
+
docs: {
|
832
715
|
category: ["Schema", "Operations"],
|
833
|
-
description: "
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
)
|
716
|
+
description: "Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation selections and more.",
|
717
|
+
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
718
|
+
examples: [
|
719
|
+
{
|
720
|
+
title: "Incorrect",
|
721
|
+
usage: [{ fields: [Kind4.OBJECT_TYPE_DEFINITION] }],
|
722
|
+
code: (
|
723
|
+
/* GraphQL */
|
724
|
+
`
|
725
|
+
type User {
|
726
|
+
password: String
|
727
|
+
firstName: String! # should be before "password"
|
728
|
+
age: Int # should be before "firstName"
|
729
|
+
lastName: String!
|
730
|
+
}
|
731
|
+
`
|
732
|
+
)
|
733
|
+
},
|
734
|
+
{
|
735
|
+
title: "Correct",
|
736
|
+
usage: [{ fields: [Kind4.OBJECT_TYPE_DEFINITION] }],
|
737
|
+
code: (
|
738
|
+
/* GraphQL */
|
739
|
+
`
|
740
|
+
type User {
|
741
|
+
age: Int
|
742
|
+
firstName: String!
|
743
|
+
lastName: String!
|
744
|
+
password: String
|
745
|
+
}
|
746
|
+
`
|
747
|
+
)
|
748
|
+
},
|
749
|
+
{
|
750
|
+
title: "Incorrect",
|
751
|
+
usage: [{ values: !0 }],
|
752
|
+
code: (
|
753
|
+
/* GraphQL */
|
754
|
+
`
|
755
|
+
enum Role {
|
756
|
+
SUPER_ADMIN
|
757
|
+
ADMIN # should be before "SUPER_ADMIN"
|
758
|
+
USER
|
759
|
+
GOD # should be before "USER"
|
760
|
+
}
|
761
|
+
`
|
762
|
+
)
|
763
|
+
},
|
764
|
+
{
|
765
|
+
title: "Correct",
|
766
|
+
usage: [{ values: !0 }],
|
767
|
+
code: (
|
768
|
+
/* GraphQL */
|
769
|
+
`
|
770
|
+
enum Role {
|
771
|
+
ADMIN
|
772
|
+
GOD
|
773
|
+
SUPER_ADMIN
|
774
|
+
USER
|
775
|
+
}
|
776
|
+
`
|
777
|
+
)
|
778
|
+
},
|
779
|
+
{
|
780
|
+
title: "Incorrect",
|
781
|
+
usage: [{ selections: [Kind4.OPERATION_DEFINITION] }],
|
782
|
+
code: (
|
783
|
+
/* GraphQL */
|
784
|
+
`
|
785
|
+
query {
|
786
|
+
me {
|
787
|
+
firstName
|
788
|
+
lastName
|
789
|
+
email # should be before "lastName"
|
790
|
+
}
|
791
|
+
}
|
792
|
+
`
|
793
|
+
)
|
794
|
+
},
|
795
|
+
{
|
796
|
+
title: "Correct",
|
797
|
+
usage: [{ selections: [Kind4.OPERATION_DEFINITION] }],
|
798
|
+
code: (
|
799
|
+
/* GraphQL */
|
800
|
+
`
|
801
|
+
query {
|
802
|
+
me {
|
803
|
+
email
|
804
|
+
firstName
|
805
|
+
lastName
|
806
|
+
}
|
807
|
+
}
|
808
|
+
`
|
809
|
+
)
|
810
|
+
}
|
811
|
+
],
|
812
|
+
configOptions: {
|
813
|
+
schema: [
|
814
|
+
{
|
815
|
+
definitions: !0,
|
816
|
+
fields: fieldsEnum,
|
817
|
+
values: !0,
|
818
|
+
arguments: argumentsEnum,
|
819
|
+
groups: ["id", "*", "createdAt", "updatedAt"]
|
820
|
+
}
|
821
|
+
],
|
822
|
+
operations: [
|
823
|
+
{
|
824
|
+
definitions: !0,
|
825
|
+
selections: selectionsEnum,
|
826
|
+
variables: !0,
|
827
|
+
arguments: [Kind4.FIELD, Kind4.DIRECTIVE],
|
828
|
+
groups: ["id", "*", "createdAt", "updatedAt"]
|
829
|
+
}
|
830
|
+
]
|
831
|
+
}
|
832
|
+
},
|
833
|
+
messages: {
|
834
|
+
[RULE_ID]: "{{ currNode }} should be before {{ prevNode }}"
|
835
|
+
},
|
836
|
+
schema
|
837
|
+
},
|
838
|
+
create(context) {
|
839
|
+
let sourceCode = context.getSourceCode();
|
840
|
+
function isNodeAndCommentOnSameLine(node, comment) {
|
841
|
+
return node.loc.end.line === comment.loc.start.line;
|
842
|
+
}
|
843
|
+
function getBeforeComments(node) {
|
844
|
+
let commentsBefore = sourceCode.getCommentsBefore(node);
|
845
|
+
if (commentsBefore.length === 0)
|
846
|
+
return [];
|
847
|
+
let tokenBefore = sourceCode.getTokenBefore(node);
|
848
|
+
if (tokenBefore)
|
849
|
+
return commentsBefore.filter((comment) => !isNodeAndCommentOnSameLine(tokenBefore, comment));
|
850
|
+
let filteredComments = [], nodeLine = node.loc.start.line;
|
851
|
+
for (let i = commentsBefore.length - 1; i >= 0; i -= 1) {
|
852
|
+
let comment = commentsBefore[i];
|
853
|
+
if (nodeLine - comment.loc.start.line - filteredComments.length > 1)
|
854
|
+
break;
|
855
|
+
filteredComments.unshift(comment);
|
856
|
+
}
|
857
|
+
return filteredComments;
|
858
|
+
}
|
859
|
+
function getRangeWithComments(node) {
|
860
|
+
node.kind === Kind4.VARIABLE && (node = node.parent);
|
861
|
+
let [firstBeforeComment] = getBeforeComments(node), [firstAfterComment] = sourceCode.getCommentsAfter(node), from = firstBeforeComment || node, to = firstAfterComment && isNodeAndCommentOnSameLine(node, firstAfterComment) ? firstAfterComment : node;
|
862
|
+
return [from.range[0], to.range[1]];
|
863
|
+
}
|
864
|
+
function checkNodes(nodes = []) {
|
865
|
+
for (let i = 1; i < nodes.length; i += 1) {
|
866
|
+
let currNode = nodes[i], currName = "alias" in currNode && currNode.alias?.value || "name" in currNode && currNode.name?.value;
|
867
|
+
if (!currName)
|
868
|
+
continue;
|
869
|
+
let prevNode = nodes[i - 1], prevName = "alias" in prevNode && prevNode.alias?.value || "name" in prevNode && prevNode.name?.value;
|
870
|
+
if (prevName) {
|
871
|
+
let compareResult = prevName.localeCompare(currName), { groups } = opts, shouldSortByGroup = !1;
|
872
|
+
if (groups?.length) {
|
873
|
+
if (!groups.includes("*"))
|
874
|
+
throw new Error("`groups` option should contain `*` string.");
|
875
|
+
let indexForPrev = groups.indexOf(prevName);
|
876
|
+
indexForPrev === -1 && (indexForPrev = groups.indexOf("*"));
|
877
|
+
let indexForCurr = groups.indexOf(currName);
|
878
|
+
if (indexForCurr === -1 && (indexForCurr = groups.indexOf("*")), shouldSortByGroup = indexForPrev - indexForCurr > 0, indexForPrev < indexForCurr)
|
879
|
+
continue;
|
880
|
+
}
|
881
|
+
if (!shouldSortByGroup && !(compareResult === 1) && (!(compareResult === 0) || !prevNode.kind.endsWith("Extension") || currNode.kind.endsWith("Extension")))
|
882
|
+
continue;
|
883
|
+
}
|
884
|
+
context.report({
|
885
|
+
// @ts-expect-error can't be undefined
|
886
|
+
node: "alias" in currNode && currNode.alias || currNode.name,
|
887
|
+
messageId: RULE_ID,
|
888
|
+
data: {
|
889
|
+
currNode: displayNodeName(currNode),
|
890
|
+
prevNode: prevName ? displayNodeName(prevNode) : lowerCase2(prevNode.kind)
|
891
|
+
},
|
892
|
+
*fix(fixer) {
|
893
|
+
let prevRange = getRangeWithComments(prevNode), currRange = getRangeWithComments(currNode);
|
894
|
+
yield fixer.replaceTextRange(
|
895
|
+
prevRange,
|
896
|
+
sourceCode.getText({ range: currRange })
|
897
|
+
), yield fixer.replaceTextRange(
|
898
|
+
currRange,
|
899
|
+
sourceCode.getText({ range: prevRange })
|
900
|
+
);
|
901
|
+
}
|
902
|
+
});
|
903
|
+
}
|
904
|
+
}
|
905
|
+
let opts = context.options[0], fields = new Set(opts.fields ?? []), listeners = {}, fieldsSelector = [
|
906
|
+
fields.has(Kind4.OBJECT_TYPE_DEFINITION) && [
|
907
|
+
Kind4.OBJECT_TYPE_DEFINITION,
|
908
|
+
Kind4.OBJECT_TYPE_EXTENSION
|
909
|
+
],
|
910
|
+
fields.has(Kind4.INTERFACE_TYPE_DEFINITION) && [
|
911
|
+
Kind4.INTERFACE_TYPE_DEFINITION,
|
912
|
+
Kind4.INTERFACE_TYPE_EXTENSION
|
913
|
+
],
|
914
|
+
fields.has(Kind4.INPUT_OBJECT_TYPE_DEFINITION) && [
|
915
|
+
Kind4.INPUT_OBJECT_TYPE_DEFINITION,
|
916
|
+
Kind4.INPUT_OBJECT_TYPE_EXTENSION
|
917
|
+
]
|
918
|
+
].filter(truthy).flat().join(","), selectionsSelector = opts.selections?.join(","), argumentsSelector = opts.arguments?.join(",");
|
919
|
+
if (fieldsSelector && (listeners[fieldsSelector] = (node) => {
|
920
|
+
checkNodes(node.fields);
|
921
|
+
}), opts.values) {
|
922
|
+
let enumValuesSelector = [Kind4.ENUM_TYPE_DEFINITION, Kind4.ENUM_TYPE_EXTENSION].join(",");
|
923
|
+
listeners[enumValuesSelector] = (node) => {
|
924
|
+
checkNodes(node.values);
|
925
|
+
};
|
926
|
+
}
|
927
|
+
return selectionsSelector && (listeners[`:matches(${selectionsSelector}) SelectionSet`] = (node) => {
|
928
|
+
checkNodes(node.selections);
|
929
|
+
}), opts.variables && (listeners.OperationDefinition = (node) => {
|
930
|
+
checkNodes(node.variableDefinitions?.map((varDef) => varDef.variable));
|
931
|
+
}), argumentsSelector && (listeners[argumentsSelector] = (node) => {
|
932
|
+
checkNodes(node.arguments);
|
933
|
+
}), opts.definitions && (listeners.Document = (node) => {
|
934
|
+
checkNodes(node.definitions);
|
935
|
+
}), listeners;
|
936
|
+
}
|
937
|
+
};
|
938
|
+
|
939
|
+
// src/rules/description-style.ts
|
940
|
+
var schema2 = {
|
941
|
+
type: "array",
|
942
|
+
maxItems: 1,
|
943
|
+
items: {
|
944
|
+
type: "object",
|
945
|
+
additionalProperties: !1,
|
946
|
+
minProperties: 1,
|
947
|
+
properties: {
|
948
|
+
style: {
|
949
|
+
enum: ["block", "inline"],
|
950
|
+
default: "block"
|
951
|
+
}
|
952
|
+
}
|
953
|
+
}
|
954
|
+
}, rule2 = {
|
955
|
+
meta: {
|
956
|
+
type: "suggestion",
|
957
|
+
hasSuggestions: !0,
|
958
|
+
docs: {
|
959
|
+
examples: [
|
960
|
+
{
|
961
|
+
title: "Incorrect",
|
962
|
+
usage: [{ style: "inline" }],
|
963
|
+
code: (
|
964
|
+
/* GraphQL */
|
965
|
+
`
|
966
|
+
""" Description """
|
967
|
+
type someTypeName {
|
968
|
+
# ...
|
969
|
+
}
|
970
|
+
`
|
971
|
+
)
|
972
|
+
},
|
973
|
+
{
|
974
|
+
title: "Correct",
|
975
|
+
usage: [{ style: "inline" }],
|
976
|
+
code: (
|
977
|
+
/* GraphQL */
|
978
|
+
`
|
979
|
+
" Description "
|
980
|
+
type someTypeName {
|
981
|
+
# ...
|
982
|
+
}
|
983
|
+
`
|
984
|
+
)
|
985
|
+
}
|
986
|
+
],
|
987
|
+
description: "Require all comments to follow the same style (either block or inline).",
|
988
|
+
category: "Schema",
|
989
|
+
url: "https://the-guild.dev/graphql/eslint/rules/description-style",
|
990
|
+
recommended: !0
|
991
|
+
},
|
992
|
+
schema: schema2
|
993
|
+
},
|
994
|
+
create(context) {
|
995
|
+
let { style = "block" } = context.options[0] || {}, isBlock = style === "block";
|
996
|
+
return {
|
997
|
+
[`.description[type=StringValue][block!=${isBlock}]`](node) {
|
998
|
+
context.report({
|
999
|
+
loc: isBlock ? node.loc : node.loc.start,
|
1000
|
+
message: `Unexpected ${isBlock ? "inline" : "block"} description for ${getNodeName(
|
1001
|
+
node.parent
|
1002
|
+
)}`,
|
1003
|
+
suggest: [
|
1004
|
+
{
|
1005
|
+
desc: `Change to ${isBlock ? "block" : "inline"} style description`,
|
1006
|
+
fix(fixer) {
|
1007
|
+
let originalText = context.getSourceCode().getText(node), newText = isBlock ? originalText.replace(/(^")|("$)/g, '"""') : originalText.replace(/(^""")|("""$)/g, '"').replace(/\s+/g, " ");
|
1008
|
+
return fixer.replaceText(node, newText);
|
1009
|
+
}
|
1010
|
+
}
|
1011
|
+
]
|
1012
|
+
});
|
1013
|
+
}
|
1014
|
+
};
|
1015
|
+
}
|
1016
|
+
};
|
1017
|
+
|
1018
|
+
// src/rules/graphql-js-validation.ts
|
1019
|
+
import {
|
1020
|
+
Kind as Kind5,
|
1021
|
+
validate,
|
1022
|
+
visit as visit3
|
1023
|
+
} from "graphql";
|
1024
|
+
import {
|
1025
|
+
ExecutableDefinitionsRule,
|
1026
|
+
FieldsOnCorrectTypeRule,
|
1027
|
+
FragmentsOnCompositeTypesRule,
|
1028
|
+
KnownArgumentNamesRule,
|
1029
|
+
KnownDirectivesRule,
|
1030
|
+
KnownFragmentNamesRule,
|
1031
|
+
KnownTypeNamesRule,
|
1032
|
+
LoneAnonymousOperationRule,
|
1033
|
+
LoneSchemaDefinitionRule,
|
1034
|
+
NoFragmentCyclesRule,
|
1035
|
+
NoUndefinedVariablesRule,
|
1036
|
+
NoUnusedFragmentsRule,
|
1037
|
+
NoUnusedVariablesRule,
|
1038
|
+
OverlappingFieldsCanBeMergedRule,
|
1039
|
+
PossibleFragmentSpreadsRule,
|
1040
|
+
PossibleTypeExtensionsRule,
|
1041
|
+
ProvidedRequiredArgumentsRule,
|
1042
|
+
ScalarLeafsRule,
|
1043
|
+
SingleFieldSubscriptionsRule,
|
1044
|
+
UniqueArgumentNamesRule,
|
1045
|
+
UniqueDirectiveNamesRule,
|
1046
|
+
UniqueDirectivesPerLocationRule,
|
1047
|
+
UniqueFieldDefinitionNamesRule,
|
1048
|
+
UniqueInputFieldNamesRule,
|
1049
|
+
UniqueOperationTypesRule,
|
1050
|
+
UniqueTypeNamesRule,
|
1051
|
+
UniqueVariableNamesRule,
|
1052
|
+
ValuesOfCorrectTypeRule,
|
1053
|
+
VariablesAreInputTypesRule,
|
1054
|
+
VariablesInAllowedPositionRule
|
1055
|
+
} from "graphql/validation/index.js";
|
1056
|
+
import { validateSDL } from "graphql/validation/validate.js";
|
1057
|
+
function validateDocument({
|
1058
|
+
context,
|
1059
|
+
schema: schema15 = null,
|
1060
|
+
documentNode,
|
1061
|
+
rule: rule35,
|
1062
|
+
hasDidYouMeanSuggestions
|
1063
|
+
}) {
|
1064
|
+
if (documentNode.definitions.length !== 0)
|
1065
|
+
try {
|
1066
|
+
let validationErrors = schema15 ? validate(schema15, documentNode, [rule35]) : validateSDL(documentNode, null, [rule35]);
|
1067
|
+
for (let error of validationErrors) {
|
1068
|
+
let { line, column } = error.locations[0], sourceCode = context.getSourceCode(), { tokens } = sourceCode.ast, token = tokens.find(
|
1069
|
+
(token2) => token2.loc.start.line === line && token2.loc.start.column === column - 1
|
1070
|
+
), loc = {
|
1071
|
+
line,
|
1072
|
+
column: column - 1
|
1073
|
+
};
|
1074
|
+
token && (loc = // if cursor on `@` symbol than use next node
|
1075
|
+
token.type === "@" ? sourceCode.getNodeByRangeIndex(token.range[1] + 1).loc : token.loc);
|
1076
|
+
let didYouMeanContent = error.message.match(/Did you mean (?<content>.*)\?$/)?.groups.content, matches = didYouMeanContent ? [...didYouMeanContent.matchAll(/"(?<name>[^"]*)"/g)] : [];
|
1077
|
+
context.report({
|
1078
|
+
loc,
|
1079
|
+
message: error.message,
|
1080
|
+
suggest: hasDidYouMeanSuggestions ? matches.map((match) => {
|
1081
|
+
let { name } = match.groups;
|
1082
|
+
return {
|
1083
|
+
desc: `Rename to \`${name}\``,
|
1084
|
+
fix: (fixer) => fixer.replaceText(token, name)
|
1085
|
+
};
|
1086
|
+
}) : []
|
1087
|
+
});
|
1088
|
+
}
|
1089
|
+
} catch (error) {
|
1090
|
+
context.report({
|
1091
|
+
loc: REPORT_ON_FIRST_CHARACTER,
|
1092
|
+
message: error.message
|
1093
|
+
});
|
1094
|
+
}
|
1095
|
+
}
|
1096
|
+
var getFragmentDefsAndFragmentSpreads = (node) => {
|
1097
|
+
let fragmentDefs = /* @__PURE__ */ new Set(), fragmentSpreads = /* @__PURE__ */ new Set();
|
1098
|
+
return visit3(node, {
|
1099
|
+
FragmentDefinition(node2) {
|
1100
|
+
fragmentDefs.add(node2.name.value);
|
1101
|
+
},
|
1102
|
+
FragmentSpread(node2) {
|
1103
|
+
fragmentSpreads.add(node2.name.value);
|
1104
|
+
}
|
1105
|
+
}), { fragmentDefs, fragmentSpreads };
|
1106
|
+
}, getMissingFragments = (node) => {
|
1107
|
+
let { fragmentDefs, fragmentSpreads } = getFragmentDefsAndFragmentSpreads(node);
|
1108
|
+
return [...fragmentSpreads].filter((name) => !fragmentDefs.has(name));
|
1109
|
+
}, handleMissingFragments = ({ ruleId, context, node }) => {
|
1110
|
+
let missingFragments = getMissingFragments(node);
|
1111
|
+
if (missingFragments.length > 0) {
|
1112
|
+
let siblings = requireSiblingsOperations(ruleId, context), fragmentsToAdd = [];
|
1113
|
+
for (let fragmentName of missingFragments) {
|
1114
|
+
let [foundFragment] = siblings.getFragment(fragmentName).map((source) => source.document);
|
1115
|
+
foundFragment && fragmentsToAdd.push(foundFragment);
|
1116
|
+
}
|
1117
|
+
if (fragmentsToAdd.length > 0)
|
1118
|
+
return handleMissingFragments({
|
1119
|
+
ruleId,
|
1120
|
+
context,
|
1121
|
+
node: {
|
1122
|
+
kind: Kind5.DOCUMENT,
|
1123
|
+
definitions: [...node.definitions, ...fragmentsToAdd]
|
1124
|
+
}
|
1125
|
+
});
|
1126
|
+
}
|
1127
|
+
return node;
|
1128
|
+
}, validationToRule = ({
|
1129
|
+
ruleId,
|
1130
|
+
rule: rule35,
|
1131
|
+
getDocumentNode,
|
1132
|
+
schema: schema15 = [],
|
1133
|
+
hasDidYouMeanSuggestions
|
1134
|
+
}, docs) => ({
|
1135
|
+
[ruleId]: {
|
1136
|
+
meta: {
|
1137
|
+
docs: {
|
1138
|
+
recommended: !0,
|
1139
|
+
...docs,
|
1140
|
+
graphQLJSRuleName: rule35.name,
|
1141
|
+
url: `https://the-guild.dev/graphql/eslint/rules/${ruleId}`,
|
1142
|
+
description: `${docs.description}
|
1143
|
+
> This rule is a wrapper around a \`graphql-js\` validation function.`
|
1144
|
+
},
|
1145
|
+
schema: schema15,
|
1146
|
+
hasSuggestions: hasDidYouMeanSuggestions
|
1147
|
+
},
|
1148
|
+
create(context) {
|
1149
|
+
return {
|
1150
|
+
Document(node) {
|
1151
|
+
let schema16 = docs.requiresSchema ? requireGraphQLSchemaFromContext(ruleId, context) : null, documentNode = getDocumentNode ? getDocumentNode({ ruleId, context, node: node.rawNode() }) : node.rawNode();
|
1152
|
+
validateDocument({
|
1153
|
+
context,
|
1154
|
+
schema: schema16,
|
1155
|
+
documentNode,
|
1156
|
+
rule: rule35,
|
1157
|
+
hasDidYouMeanSuggestions
|
1158
|
+
});
|
1159
|
+
}
|
1160
|
+
};
|
1161
|
+
}
|
1162
|
+
}
|
1163
|
+
}), GRAPHQL_JS_VALIDATIONS = Object.assign(
|
1164
|
+
{},
|
1165
|
+
validationToRule(
|
1166
|
+
{
|
1167
|
+
ruleId: "executable-definitions",
|
1168
|
+
rule: ExecutableDefinitionsRule
|
1169
|
+
},
|
1170
|
+
{
|
1171
|
+
category: "Operations",
|
1172
|
+
description: "A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.",
|
1173
|
+
requiresSchema: !0
|
1174
|
+
}
|
1175
|
+
),
|
1176
|
+
validationToRule(
|
1177
|
+
{
|
1178
|
+
ruleId: "fields-on-correct-type",
|
1179
|
+
rule: FieldsOnCorrectTypeRule,
|
1180
|
+
hasDidYouMeanSuggestions: !0
|
1181
|
+
},
|
1182
|
+
{
|
1183
|
+
category: "Operations",
|
1184
|
+
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`.",
|
1185
|
+
requiresSchema: !0
|
1186
|
+
}
|
1187
|
+
),
|
1188
|
+
validationToRule(
|
1189
|
+
{
|
1190
|
+
ruleId: "fragments-on-composite-type",
|
1191
|
+
rule: FragmentsOnCompositeTypesRule
|
1192
|
+
},
|
1193
|
+
{
|
1194
|
+
category: "Operations",
|
1195
|
+
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.",
|
1196
|
+
requiresSchema: !0
|
1197
|
+
}
|
1198
|
+
),
|
1199
|
+
validationToRule(
|
1200
|
+
{
|
1201
|
+
ruleId: "known-argument-names",
|
1202
|
+
rule: KnownArgumentNamesRule,
|
1203
|
+
hasDidYouMeanSuggestions: !0
|
1204
|
+
},
|
1205
|
+
{
|
1206
|
+
category: ["Schema", "Operations"],
|
1207
|
+
description: "A GraphQL field is only valid if all supplied arguments are defined by that field.",
|
1208
|
+
requiresSchema: !0
|
1209
|
+
}
|
1210
|
+
),
|
1211
|
+
validationToRule(
|
1212
|
+
{
|
1213
|
+
ruleId: "known-directives",
|
1214
|
+
rule: KnownDirectivesRule,
|
1215
|
+
getDocumentNode({ context, node: documentNode }) {
|
1216
|
+
let { ignoreClientDirectives = [] } = context.options[0] || {};
|
1217
|
+
if (ignoreClientDirectives.length === 0)
|
1218
|
+
return documentNode;
|
1219
|
+
let filterDirectives = (node) => ({
|
1220
|
+
...node,
|
1221
|
+
directives: node.directives?.filter(
|
1222
|
+
(directive) => !ignoreClientDirectives.includes(directive.name.value)
|
1223
|
+
)
|
850
1224
|
});
|
851
1225
|
return visit3(documentNode, {
|
852
1226
|
Field: filterDirectives,
|
@@ -1028,13 +1402,13 @@ var getFragmentDefsAndFragmentSpreads = (node) => {
|
|
1028
1402
|
delete FilePathToDocumentsMap[currentFilePath];
|
1029
1403
|
for (let [filePath, documents] of Object.entries(FilePathToDocumentsMap))
|
1030
1404
|
if (getMissingFragments({
|
1031
|
-
kind:
|
1405
|
+
kind: Kind5.DOCUMENT,
|
1032
1406
|
definitions: documents
|
1033
1407
|
}).some(
|
1034
1408
|
(fragment) => fragmentDefs.has(fragment)
|
1035
1409
|
))
|
1036
1410
|
return getParentNode(filePath, {
|
1037
|
-
kind:
|
1411
|
+
kind: Kind5.DOCUMENT,
|
1038
1412
|
definitions: [...node2.definitions, ...documents]
|
1039
1413
|
});
|
1040
1414
|
return node2;
|
@@ -1044,585 +1418,211 @@ var getFragmentDefsAndFragmentSpreads = (node) => {
|
|
1044
1418
|
},
|
1045
1419
|
{
|
1046
1420
|
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
|
1421
|
+
description: "A GraphQL document is only valid if all fragment definitions are spread within operations, or spread within other fragments spread within operations.",
|
1422
|
+
requiresSchema: !0,
|
1423
|
+
requiresSiblings: !0
|
1164
1424
|
}
|
1165
1425
|
),
|
1166
1426
|
validationToRule(
|
1167
1427
|
{
|
1168
|
-
ruleId: "
|
1169
|
-
rule:
|
1428
|
+
ruleId: "no-unused-variables",
|
1429
|
+
rule: NoUnusedVariablesRule,
|
1430
|
+
getDocumentNode: handleMissingFragments
|
1170
1431
|
},
|
1171
1432
|
{
|
1172
|
-
category: "
|
1173
|
-
description: "A GraphQL
|
1433
|
+
category: "Operations",
|
1434
|
+
description: "A GraphQL operation is only valid if all variables defined by an operation are used, either directly or within a spread fragment.",
|
1435
|
+
requiresSchema: !0,
|
1436
|
+
requiresSiblings: !0
|
1174
1437
|
}
|
1175
1438
|
),
|
1176
1439
|
validationToRule(
|
1177
1440
|
{
|
1178
|
-
ruleId: "
|
1179
|
-
rule:
|
1441
|
+
ruleId: "overlapping-fields-can-be-merged",
|
1442
|
+
rule: OverlappingFieldsCanBeMergedRule
|
1180
1443
|
},
|
1181
1444
|
{
|
1182
1445
|
category: "Operations",
|
1183
|
-
description: "A
|
1446
|
+
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.",
|
1447
|
+
requiresSchema: !0
|
1184
1448
|
}
|
1185
1449
|
),
|
1186
1450
|
validationToRule(
|
1187
1451
|
{
|
1188
|
-
ruleId: "
|
1189
|
-
rule:
|
1452
|
+
ruleId: "possible-fragment-spread",
|
1453
|
+
rule: PossibleFragmentSpreadsRule
|
1190
1454
|
},
|
1191
1455
|
{
|
1192
|
-
category: "
|
1193
|
-
description: "A
|
1456
|
+
category: "Operations",
|
1457
|
+
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.",
|
1458
|
+
requiresSchema: !0
|
1194
1459
|
}
|
1195
1460
|
),
|
1196
1461
|
validationToRule(
|
1197
1462
|
{
|
1198
|
-
ruleId: "
|
1199
|
-
rule:
|
1463
|
+
ruleId: "possible-type-extension",
|
1464
|
+
rule: PossibleTypeExtensionsRule,
|
1465
|
+
hasDidYouMeanSuggestions: !0
|
1200
1466
|
},
|
1201
1467
|
{
|
1202
1468
|
category: "Schema",
|
1203
|
-
description: "A
|
1469
|
+
description: "A type extension is only valid if the type is defined and has the same kind.",
|
1470
|
+
recommended: !0,
|
1471
|
+
requiresSchema: !0
|
1204
1472
|
}
|
1205
1473
|
),
|
1206
1474
|
validationToRule(
|
1207
1475
|
{
|
1208
|
-
ruleId: "
|
1209
|
-
rule:
|
1476
|
+
ruleId: "provided-required-arguments",
|
1477
|
+
rule: ProvidedRequiredArgumentsRule
|
1210
1478
|
},
|
1211
1479
|
{
|
1212
|
-
category: "Operations",
|
1213
|
-
description: "A
|
1480
|
+
category: ["Schema", "Operations"],
|
1481
|
+
description: "A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.",
|
1214
1482
|
requiresSchema: !0
|
1215
1483
|
}
|
1216
1484
|
),
|
1217
1485
|
validationToRule(
|
1218
1486
|
{
|
1219
|
-
ruleId: "
|
1220
|
-
rule:
|
1487
|
+
ruleId: "scalar-leafs",
|
1488
|
+
rule: ScalarLeafsRule,
|
1221
1489
|
hasDidYouMeanSuggestions: !0
|
1222
1490
|
},
|
1223
1491
|
{
|
1224
1492
|
category: "Operations",
|
1225
|
-
description: "A GraphQL document is only
|
1493
|
+
description: "A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.",
|
1226
1494
|
requiresSchema: !0
|
1227
1495
|
}
|
1228
1496
|
),
|
1229
1497
|
validationToRule(
|
1230
1498
|
{
|
1231
|
-
ruleId: "
|
1232
|
-
rule:
|
1499
|
+
ruleId: "one-field-subscriptions",
|
1500
|
+
rule: SingleFieldSubscriptionsRule
|
1233
1501
|
},
|
1234
1502
|
{
|
1235
1503
|
category: "Operations",
|
1236
|
-
description: "A GraphQL
|
1504
|
+
description: "A GraphQL subscription is valid only if it contains a single root field.",
|
1237
1505
|
requiresSchema: !0
|
1238
1506
|
}
|
1239
1507
|
),
|
1240
1508
|
validationToRule(
|
1241
1509
|
{
|
1242
|
-
ruleId: "
|
1243
|
-
rule:
|
1510
|
+
ruleId: "unique-argument-names",
|
1511
|
+
rule: UniqueArgumentNamesRule
|
1244
1512
|
},
|
1245
1513
|
{
|
1246
1514
|
category: "Operations",
|
1247
|
-
description: "
|
1515
|
+
description: "A GraphQL field or directive is only valid if all supplied arguments are uniquely named.",
|
1248
1516
|
requiresSchema: !0
|
1249
1517
|
}
|
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
|
-
}
|
1518
|
+
),
|
1519
|
+
validationToRule(
|
1520
|
+
{
|
1521
|
+
ruleId: "unique-directive-names",
|
1522
|
+
rule: UniqueDirectiveNamesRule
|
1523
|
+
},
|
1524
|
+
{
|
1525
|
+
category: "Schema",
|
1526
|
+
description: "A GraphQL document is only valid if all defined directives have unique names."
|
1317
1527
|
}
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
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
|
-
}
|
1528
|
+
),
|
1529
|
+
validationToRule(
|
1530
|
+
{
|
1531
|
+
ruleId: "unique-directive-names-per-location",
|
1532
|
+
rule: UniqueDirectivesPerLocationRule
|
1533
|
+
},
|
1534
|
+
{
|
1535
|
+
category: ["Schema", "Operations"],
|
1536
|
+
description: "A GraphQL document is only valid if all non-repeatable directives at a given location are uniquely named.",
|
1537
|
+
requiresSchema: !0
|
1538
|
+
}
|
1539
|
+
),
|
1540
|
+
validationToRule(
|
1541
|
+
{
|
1542
|
+
ruleId: "unique-field-definition-names",
|
1543
|
+
rule: UniqueFieldDefinitionNamesRule
|
1441
1544
|
},
|
1442
|
-
|
1443
|
-
|
1545
|
+
{
|
1546
|
+
category: "Schema",
|
1547
|
+
description: "A GraphQL complex type is only valid if all its fields are uniquely named."
|
1548
|
+
}
|
1549
|
+
),
|
1550
|
+
validationToRule(
|
1551
|
+
{
|
1552
|
+
ruleId: "unique-input-field-names",
|
1553
|
+
rule: UniqueInputFieldNamesRule
|
1444
1554
|
},
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
let sourceCode = context.getSourceCode();
|
1449
|
-
function isNodeAndCommentOnSameLine(node, comment) {
|
1450
|
-
return node.loc.end.line === comment.loc.start.line;
|
1555
|
+
{
|
1556
|
+
category: "Operations",
|
1557
|
+
description: "A GraphQL input object value is only valid if all supplied fields are uniquely named."
|
1451
1558
|
}
|
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;
|
1559
|
+
),
|
1560
|
+
validationToRule(
|
1561
|
+
{
|
1562
|
+
ruleId: "unique-operation-types",
|
1563
|
+
rule: UniqueOperationTypesRule
|
1564
|
+
},
|
1565
|
+
{
|
1566
|
+
category: "Schema",
|
1567
|
+
description: "A GraphQL document is only valid if it has only one type per operation."
|
1467
1568
|
}
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1569
|
+
),
|
1570
|
+
validationToRule(
|
1571
|
+
{
|
1572
|
+
ruleId: "unique-type-names",
|
1573
|
+
rule: UniqueTypeNamesRule
|
1574
|
+
},
|
1575
|
+
{
|
1576
|
+
category: "Schema",
|
1577
|
+
description: "A GraphQL document is only valid if all defined types have unique names."
|
1472
1578
|
}
|
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
|
-
}
|
1579
|
+
),
|
1580
|
+
validationToRule(
|
1581
|
+
{
|
1582
|
+
ruleId: "unique-variable-names",
|
1583
|
+
rule: UniqueVariableNamesRule
|
1584
|
+
},
|
1585
|
+
{
|
1586
|
+
category: "Operations",
|
1587
|
+
description: "A GraphQL operation is only valid if all its variables are uniquely named.",
|
1588
|
+
requiresSchema: !0
|
1513
1589
|
}
|
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
|
-
};
|
1590
|
+
),
|
1591
|
+
validationToRule(
|
1592
|
+
{
|
1593
|
+
ruleId: "value-literals-of-correct-type",
|
1594
|
+
rule: ValuesOfCorrectTypeRule,
|
1595
|
+
hasDidYouMeanSuggestions: !0
|
1596
|
+
},
|
1597
|
+
{
|
1598
|
+
category: "Operations",
|
1599
|
+
description: "A GraphQL document is only valid if all value literals are of the type expected at their position.",
|
1600
|
+
requiresSchema: !0
|
1535
1601
|
}
|
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
|
-
}
|
1602
|
+
),
|
1603
|
+
validationToRule(
|
1604
|
+
{
|
1605
|
+
ruleId: "variables-are-input-types",
|
1606
|
+
rule: VariablesAreInputTypesRule
|
1607
|
+
},
|
1608
|
+
{
|
1609
|
+
category: "Operations",
|
1610
|
+
description: "A GraphQL operation is only valid if all the variables it defines are of input types (scalar, enum, or input object).",
|
1611
|
+
requiresSchema: !0
|
1561
1612
|
}
|
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
|
1613
|
+
),
|
1614
|
+
validationToRule(
|
1615
|
+
{
|
1616
|
+
ruleId: "variables-in-allowed-position",
|
1617
|
+
rule: VariablesInAllowedPositionRule
|
1600
1618
|
},
|
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
|
-
};
|
1619
|
+
{
|
1620
|
+
category: "Operations",
|
1621
|
+
description: "Variables passed to field arguments conform to type.",
|
1622
|
+
requiresSchema: !0
|
1623
|
+
}
|
1624
|
+
)
|
1625
|
+
);
|
1626
1626
|
|
1627
1627
|
// src/rules/input-name.ts
|
1628
1628
|
import {
|
@@ -3209,8 +3209,7 @@ function getReachableTypes(schema15) {
|
|
3209
3209
|
let { objects, interfaces } = schema15.getImplementations(type);
|
3210
3210
|
for (let { astNode } of [...objects, ...interfaces])
|
3211
3211
|
visit5(astNode, visitor);
|
3212
|
-
} else
|
3213
|
-
type?.astNode && visit5(type.astNode, visitor);
|
3212
|
+
} else type?.astNode && visit5(type.astNode, visitor);
|
3214
3213
|
}, visitor = {
|
3215
3214
|
InterfaceTypeDefinition: collect,
|
3216
3215
|
ObjectTypeDefinition: collect,
|
@@ -3615,13 +3614,13 @@ var MUST_BE_OBJECT_TYPE = "MUST_BE_OBJECT_TYPE", MUST_CONTAIN_FIELD_EDGES = "MUS
|
|
3615
3614
|
};
|
3616
3615
|
|
3617
3616
|
// src/rules/relay-edge-types.ts
|
3618
|
-
import { getDocumentNodeFromSchema } from "@graphql-tools/utils";
|
3619
3617
|
import {
|
3620
3618
|
isObjectType as isObjectType2,
|
3621
3619
|
isScalarType as isScalarType3,
|
3622
3620
|
Kind as Kind16,
|
3623
3621
|
visit as visit7
|
3624
3622
|
} from "graphql";
|
3623
|
+
import { getDocumentNodeFromSchema } from "@graphql-tools/utils";
|
3625
3624
|
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
3625
|
function getEdgeTypes(schema15) {
|
3627
3626
|
if (edgeTypesCache)
|
@@ -4019,8 +4018,8 @@ var rule22 = {
|
|
4019
4018
|
};
|
4020
4019
|
|
4021
4020
|
// src/rules/require-description.ts
|
4022
|
-
import { getRootTypeNames } from "@graphql-tools/utils";
|
4023
4021
|
import { Kind as Kind18, TokenKind as TokenKind3 } from "graphql";
|
4022
|
+
import { getRootTypeNames } from "@graphql-tools/utils";
|
4024
4023
|
var RULE_ID14 = "require-description", ALLOWED_KINDS2 = [
|
4025
4024
|
...TYPES_KINDS,
|
4026
4025
|
Kind18.DIRECTIVE_DEFINITION,
|
@@ -4321,21 +4320,17 @@ var RULE_ID16 = "require-import-fragment", SUGGESTION_ID = "add-import-expressio
|
|
4321
4320
|
for (let comment of comments) {
|
4322
4321
|
if (comment.type !== "Line" || !new RegExp(
|
4323
4322
|
`^\\s*import\\s+(${fragmentName}\\s+from\\s+)?['"]`
|
4324
|
-
).test(comment.value))
|
4325
|
-
continue;
|
4323
|
+
).test(comment.value)) continue;
|
4326
4324
|
let extractedImportPath = comment.value.match(/(["'])((?:\1|.)*?)\1/)?.[2];
|
4327
|
-
if (!extractedImportPath)
|
4328
|
-
continue;
|
4325
|
+
if (!extractedImportPath) continue;
|
4329
4326
|
let importPath = path.join(path.dirname(filePath), extractedImportPath);
|
4330
4327
|
if (fragmentsFromSiblings.some(
|
4331
4328
|
(source) => source.filePath === importPath
|
4332
|
-
))
|
4333
|
-
return;
|
4329
|
+
)) return;
|
4334
4330
|
}
|
4335
4331
|
if (fragmentsFromSiblings.some(
|
4336
4332
|
(source) => source.filePath === filePath
|
4337
|
-
))
|
4338
|
-
return;
|
4333
|
+
)) return;
|
4339
4334
|
let suggestedFilePaths = fragmentsFromSiblings.length ? fragmentsFromSiblings.map((o) => path.relative(path.dirname(filePath), o.filePath)) : ["CHANGE_ME.graphql"];
|
4340
4335
|
context.report({
|
4341
4336
|
node,
|
@@ -4493,7 +4488,6 @@ var RULE_ID18 = "require-nullable-result-in-root", rule27 = {
|
|
4493
4488
|
};
|
4494
4489
|
|
4495
4490
|
// src/rules/require-selections.ts
|
4496
|
-
import { asArray } from "@graphql-tools/utils";
|
4497
4491
|
import {
|
4498
4492
|
GraphQLInterfaceType,
|
4499
4493
|
GraphQLObjectType,
|
@@ -4503,6 +4497,7 @@ import {
|
|
4503
4497
|
visit as visit8,
|
4504
4498
|
visitWithTypeInfo as visitWithTypeInfo3
|
4505
4499
|
} from "graphql";
|
4500
|
+
import { asArray } from "@graphql-tools/utils";
|
4506
4501
|
var RULE_ID19 = "require-selections", DEFAULT_ID_FIELD_NAME = "id", schema12 = {
|
4507
4502
|
definitions: {
|
4508
4503
|
asString: {
|