Skip to content

Commit f6851fe

Browse files
committed
[RFC] Export all validation rules directly
It's become relatively standard to create a whitelist or blacklist of validation rules, and reaching into the package per rule can get messy. This exports all the rules at the higher levels of submodule and module as well to make this easier. For explaination of whitelist of blacklist: ```js // Whitelist import { specifiedRules, ScalarLeafs } from 'graphql'; // A ruleset which only runs one rule. const whitelistRules = [ ScalarLeafs ]; ``` ```js // Blacklist import { specifiedRules, ScalarLeafs } from 'graphql'; // A ruleset which only runs all but one rule. const blacklistRules = specifiedRules.filter(rule => rule !== ScalarLeafs); // Note: the wrong way to do a blacklist would be to import and specify all // but one rule. That's a whitelist and would fail to pick up any added // validation rules that may be amended to spec in the future. ```
1 parent ca70f60 commit f6851fe

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

src/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,36 @@ export type {
247247
export {
248248
validate,
249249
ValidationContext,
250+
251+
// All validation rules in the GraphQL Specification.
250252
specifiedRules,
253+
254+
// Individual validation rules.
255+
UniqueOperationNames,
256+
LoneAnonymousOperation,
257+
KnownTypeNames,
258+
FragmentsOnCompositeTypes,
259+
VariablesAreInputTypes,
260+
ScalarLeafs,
261+
FieldsOnCorrectType,
262+
UniqueFragmentNames,
263+
KnownFragmentNames,
264+
NoUnusedFragments,
265+
PossibleFragmentSpreads,
266+
NoFragmentCycles,
267+
UniqueVariableNames,
268+
NoUndefinedVariables,
269+
NoUnusedVariables,
270+
KnownDirectives,
271+
UniqueDirectivesPerLocation,
272+
KnownArgumentNames,
273+
UniqueArgumentNames,
274+
ArgumentsOfCorrectType,
275+
ProvidedNonNullArguments,
276+
DefaultValuesOfCorrectType,
277+
VariablesInAllowedPosition,
278+
OverlappingFieldsCanBeMerged,
279+
UniqueInputFieldNames,
251280
} from './validation';
252281

253282

src/validation/index.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,84 @@
88
*/
99

1010
export { validate, ValidationContext } from './validate';
11+
12+
// Spec Section: "Operation Name Uniqueness"
13+
export { UniqueOperationNames } from './rules/UniqueOperationNames';
14+
15+
// Spec Section: "Lone Anonymous Operation"
16+
export { LoneAnonymousOperation } from './rules/LoneAnonymousOperation';
17+
18+
// Spec Section: "Fragment Spread Type Existence"
19+
export { KnownTypeNames } from './rules/KnownTypeNames';
20+
21+
// Spec Section: "Fragments on Composite Types"
22+
export { FragmentsOnCompositeTypes } from './rules/FragmentsOnCompositeTypes';
23+
24+
// Spec Section: "Variables are Input Types"
25+
export { VariablesAreInputTypes } from './rules/VariablesAreInputTypes';
26+
27+
// Spec Section: "Leaf Field Selections"
28+
export { ScalarLeafs } from './rules/ScalarLeafs';
29+
30+
// Spec Section: "Field Selections on Objects, Interfaces, and Unions Types"
31+
export { FieldsOnCorrectType } from './rules/FieldsOnCorrectType';
32+
33+
// Spec Section: "Fragment Name Uniqueness"
34+
export { UniqueFragmentNames } from './rules/UniqueFragmentNames';
35+
36+
// Spec Section: "Fragment spread target defined"
37+
export { KnownFragmentNames } from './rules/KnownFragmentNames';
38+
39+
// Spec Section: "Fragments must be used"
40+
export { NoUnusedFragments } from './rules/NoUnusedFragments';
41+
42+
// Spec Section: "Fragment spread is possible"
43+
export { PossibleFragmentSpreads } from './rules/PossibleFragmentSpreads';
44+
45+
// Spec Section: "Fragments must not form cycles"
46+
export { NoFragmentCycles } from './rules/NoFragmentCycles';
47+
48+
// Spec Section: "Variable Uniqueness"
49+
export { UniqueVariableNames } from './rules/UniqueVariableNames';
50+
51+
// Spec Section: "All Variable Used Defined"
52+
export { NoUndefinedVariables } from './rules/NoUndefinedVariables';
53+
54+
// Spec Section: "All Variables Used"
55+
export { NoUnusedVariables } from './rules/NoUnusedVariables';
56+
57+
// Spec Section: "Directives Are Defined"
58+
export { KnownDirectives } from './rules/KnownDirectives';
59+
60+
// Spec Section: "Directives Are Unique Per Location"
61+
export {
62+
UniqueDirectivesPerLocation
63+
} from './rules/UniqueDirectivesPerLocation';
64+
65+
// Spec Section: "Argument Names"
66+
export { KnownArgumentNames } from './rules/KnownArgumentNames';
67+
68+
// Spec Section: "Argument Uniqueness"
69+
export { UniqueArgumentNames } from './rules/UniqueArgumentNames';
70+
71+
// Spec Section: "Argument Values Type Correctness"
72+
export { ArgumentsOfCorrectType } from './rules/ArgumentsOfCorrectType';
73+
74+
// Spec Section: "Argument Optionality"
75+
export { ProvidedNonNullArguments } from './rules/ProvidedNonNullArguments';
76+
77+
// Spec Section: "Variable Default Values Are Correctly Typed"
78+
export { DefaultValuesOfCorrectType } from './rules/DefaultValuesOfCorrectType';
79+
80+
// Spec Section: "All Variable Usages Are Allowed"
81+
export { VariablesInAllowedPosition } from './rules/VariablesInAllowedPosition';
82+
83+
// Spec Section: "Field Selection Merging"
84+
export {
85+
OverlappingFieldsCanBeMerged
86+
} from './rules/OverlappingFieldsCanBeMerged';
87+
88+
// Spec Section: "Input Object Field Uniqueness"
89+
export { UniqueInputFieldNames } from './rules/UniqueInputFieldNames';
90+
1191
export { specifiedRules } from './specifiedRules';

0 commit comments

Comments
 (0)