@graphql-eslint/eslint-plugin 3.14.0-alpha-20221222124206-b82954b â 3.14.0-alpha-20221222170519-5410a68
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/configs/schema-all.js +1 -0
- package/cjs/rules/index.js +2 -0
- package/cjs/rules/require-nullable-fields-with-oneof.js +61 -0
- package/docs/README.md +1 -0
- package/docs/rules/require-nullable-fields-with-oneof.md +38 -0
- package/package.json +1 -1
- package/typings/configs/index.d.cts +1 -0
- package/typings/configs/index.d.ts +1 -0
- package/typings/configs/schema-all.d.cts +1 -0
- package/typings/configs/schema-all.d.ts +1 -0
- package/typings/rules/index.d.cts +1 -0
- package/typings/rules/index.d.ts +1 -0
- package/typings/rules/require-nullable-fields-with-oneof.d.cts +2 -0
- package/typings/rules/require-nullable-fields-with-oneof.d.ts +2 -0
@@ -18,6 +18,7 @@ exports.default = {
|
|
18
18
|
'@graphql-eslint/no-scalar-result-type-on-mutation': 'error',
|
19
19
|
'@graphql-eslint/require-deprecation-date': 'error',
|
20
20
|
'@graphql-eslint/require-field-of-type-query-in-mutation-result': 'error',
|
21
|
+
'@graphql-eslint/require-nullable-fields-with-oneof': 'error',
|
21
22
|
},
|
22
23
|
};
|
23
24
|
module.exports = exports.default;
|
package/cjs/rules/index.js
CHANGED
@@ -30,6 +30,7 @@ const require_deprecation_reason_1 = require("./require-deprecation-reason");
|
|
30
30
|
const require_description_1 = require("./require-description");
|
31
31
|
const require_field_of_type_query_in_mutation_result_1 = require("./require-field-of-type-query-in-mutation-result");
|
32
32
|
const require_id_when_available_1 = require("./require-id-when-available");
|
33
|
+
const require_nullable_fields_with_oneof_1 = require("./require-nullable-fields-with-oneof");
|
33
34
|
const selection_set_depth_1 = require("./selection-set-depth");
|
34
35
|
const strict_id_in_types_1 = require("./strict-id-in-types");
|
35
36
|
const unique_fragment_name_1 = require("./unique-fragment-name");
|
@@ -61,6 +62,7 @@ exports.rules = {
|
|
61
62
|
'require-description': require_description_1.rule,
|
62
63
|
'require-field-of-type-query-in-mutation-result': require_field_of_type_query_in_mutation_result_1.rule,
|
63
64
|
'require-id-when-available': require_id_when_available_1.rule,
|
65
|
+
'require-nullable-fields-with-oneof': require_nullable_fields_with_oneof_1.rule,
|
64
66
|
'selection-set-depth': selection_set_depth_1.rule,
|
65
67
|
'strict-id-in-types': strict_id_in_types_1.rule,
|
66
68
|
'unique-fragment-name': unique_fragment_name_1.rule,
|
@@ -0,0 +1,61 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.rule = void 0;
|
4
|
+
const graphql_1 = require("graphql");
|
5
|
+
const RULE_ID = 'require-nullable-fields-with-oneof';
|
6
|
+
exports.rule = {
|
7
|
+
meta: {
|
8
|
+
type: 'suggestion',
|
9
|
+
docs: {
|
10
|
+
category: 'Schema',
|
11
|
+
description: 'Require are `input` or `type` fields be non nullable with `@oneOf` directive.',
|
12
|
+
url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
|
13
|
+
examples: [
|
14
|
+
{
|
15
|
+
title: 'Incorrect',
|
16
|
+
code: /* GraphQL */ `
|
17
|
+
input Input @oneOf {
|
18
|
+
foo: String!
|
19
|
+
b: Int
|
20
|
+
}
|
21
|
+
`,
|
22
|
+
},
|
23
|
+
{
|
24
|
+
title: 'Correct',
|
25
|
+
code: /* GraphQL */ `
|
26
|
+
input Input @oneOf {
|
27
|
+
foo: String
|
28
|
+
bar: Int
|
29
|
+
}
|
30
|
+
`,
|
31
|
+
},
|
32
|
+
],
|
33
|
+
},
|
34
|
+
messages: {
|
35
|
+
[RULE_ID]: 'Field `{{fieldName}}` must be nullable.',
|
36
|
+
},
|
37
|
+
schema: [],
|
38
|
+
},
|
39
|
+
create(context) {
|
40
|
+
return {
|
41
|
+
'Directive[name.value=oneOf]'(node) {
|
42
|
+
const isTypeOrInput = [
|
43
|
+
graphql_1.Kind.OBJECT_TYPE_DEFINITION,
|
44
|
+
graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
45
|
+
].includes(node.parent.kind);
|
46
|
+
if (!isTypeOrInput) {
|
47
|
+
return;
|
48
|
+
}
|
49
|
+
for (const field of node.parent.fields) {
|
50
|
+
if (field.gqlType.kind === graphql_1.Kind.NON_NULL_TYPE) {
|
51
|
+
context.report({
|
52
|
+
node: field.name,
|
53
|
+
messageId: RULE_ID,
|
54
|
+
data: { fieldName: field.name.value },
|
55
|
+
});
|
56
|
+
}
|
57
|
+
}
|
58
|
+
},
|
59
|
+
};
|
60
|
+
},
|
61
|
+
};
|
package/docs/README.md
CHANGED
@@ -58,6 +58,7 @@ Name &nbs
|
|
58
58
|
[require-description](rules/require-description.md)|Enforce descriptions in type definitions and operations.|![recommended][]|đ|đ|
|
59
59
|
[require-field-of-type-query-in-mutation-result](rules/require-field-of-type-query-in-mutation-result.md)|Allow the client in one round-trip not only to call mutation but also to get a wagon of data to update their application.|![all][]|đ|đ|
|
60
60
|
[require-id-when-available](rules/require-id-when-available.md)|Enforce selecting specific fields when they are available on the GraphQL type.|![recommended][]|đĻ|đ|đĄ
|
61
|
+
[require-nullable-fields-with-oneof](rules/require-nullable-fields-with-oneof.md)|Require are `input` or `type` fields be non nullable with `@oneOf` directive.|![all][]|đ|đ|
|
61
62
|
[scalar-leafs](rules/scalar-leafs.md)|A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.|![recommended][]|đĻ|đŽ|đĄ
|
62
63
|
[selection-set-depth](rules/selection-set-depth.md)|Limit the complexity of the GraphQL operations solely by their depth. Based on [graphql-depth-limit](https://npmjs.com/package/graphql-depth-limit).|![recommended][]|đĻ|đ|đĄ
|
63
64
|
[strict-id-in-types](rules/strict-id-in-types.md)|Requires output types to have one unique identifier unless they do not have a logical one. Exceptions can be used to ignore output types that do not have unique identifiers.|![recommended][]|đ|đ|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# `require-nullable-fields-with-oneof`
|
2
|
+
|
3
|
+
- Category: `Schema`
|
4
|
+
- Rule name: `@graphql-eslint/require-nullable-fields-with-oneof`
|
5
|
+
- Requires GraphQL Schema: `false` [âšī¸](../../README.md#extended-linting-rules-with-graphql-schema)
|
6
|
+
- Requires GraphQL Operations: `false`
|
7
|
+
[âšī¸](../../README.md#extended-linting-rules-with-siblings-operations)
|
8
|
+
|
9
|
+
Require are `input` or `type` fields be non nullable with `@oneOf` directive.
|
10
|
+
|
11
|
+
## Usage Examples
|
12
|
+
|
13
|
+
### Incorrect
|
14
|
+
|
15
|
+
```graphql
|
16
|
+
# eslint @graphql-eslint/require-nullable-fields-with-oneof: 'error'
|
17
|
+
|
18
|
+
input Input @oneOf {
|
19
|
+
foo: String!
|
20
|
+
b: Int
|
21
|
+
}
|
22
|
+
```
|
23
|
+
|
24
|
+
### Correct
|
25
|
+
|
26
|
+
```graphql
|
27
|
+
# eslint @graphql-eslint/require-nullable-fields-with-oneof: 'error'
|
28
|
+
|
29
|
+
input Input @oneOf {
|
30
|
+
foo: String
|
31
|
+
bar: Int
|
32
|
+
}
|
33
|
+
```
|
34
|
+
|
35
|
+
## Resources
|
36
|
+
|
37
|
+
- [Rule source](../../packages/plugin/src/rules/require-nullable-fields-with-oneof.ts)
|
38
|
+
- [Test source](../../packages/plugin/tests/require-nullable-fields-with-oneof.spec.ts)
|
package/package.json
CHANGED
@@ -57,6 +57,7 @@ export declare const configs: {
|
|
57
57
|
'@graphql-eslint/no-scalar-result-type-on-mutation': string;
|
58
58
|
'@graphql-eslint/require-deprecation-date': string;
|
59
59
|
'@graphql-eslint/require-field-of-type-query-in-mutation-result': string;
|
60
|
+
'@graphql-eslint/require-nullable-fields-with-oneof': string;
|
60
61
|
};
|
61
62
|
};
|
62
63
|
'operations-recommended': {
|
@@ -57,6 +57,7 @@ export declare const configs: {
|
|
57
57
|
'@graphql-eslint/no-scalar-result-type-on-mutation': string;
|
58
58
|
'@graphql-eslint/require-deprecation-date': string;
|
59
59
|
'@graphql-eslint/require-field-of-type-query-in-mutation-result': string;
|
60
|
+
'@graphql-eslint/require-nullable-fields-with-oneof': string;
|
60
61
|
};
|
61
62
|
};
|
62
63
|
'operations-recommended': {
|
@@ -10,6 +10,7 @@ declare const _default: {
|
|
10
10
|
'@graphql-eslint/no-scalar-result-type-on-mutation': string;
|
11
11
|
'@graphql-eslint/require-deprecation-date': string;
|
12
12
|
'@graphql-eslint/require-field-of-type-query-in-mutation-result': string;
|
13
|
+
'@graphql-eslint/require-nullable-fields-with-oneof': string;
|
13
14
|
};
|
14
15
|
};
|
15
16
|
export default _default;
|
@@ -10,6 +10,7 @@ declare const _default: {
|
|
10
10
|
'@graphql-eslint/no-scalar-result-type-on-mutation': string;
|
11
11
|
'@graphql-eslint/require-deprecation-date': string;
|
12
12
|
'@graphql-eslint/require-field-of-type-query-in-mutation-result': string;
|
13
|
+
'@graphql-eslint/require-nullable-fields-with-oneof': string;
|
13
14
|
};
|
14
15
|
};
|
15
16
|
export default _default;
|
@@ -87,6 +87,7 @@ export declare const rules: {
|
|
87
87
|
'require-id-when-available': import("..").GraphQLESLintRule<{
|
88
88
|
fieldName?: string | string[];
|
89
89
|
}[], true>;
|
90
|
+
'require-nullable-fields-with-oneof': import("..").GraphQLESLintRule<any[], false>;
|
90
91
|
'selection-set-depth': import("..").GraphQLESLintRule<{
|
91
92
|
ignore?: string[];
|
92
93
|
maxDepth: number;
|
package/typings/rules/index.d.ts
CHANGED
@@ -87,6 +87,7 @@ export declare const rules: {
|
|
87
87
|
'require-id-when-available': import("..").GraphQLESLintRule<{
|
88
88
|
fieldName?: string | string[];
|
89
89
|
}[], true>;
|
90
|
+
'require-nullable-fields-with-oneof': import("..").GraphQLESLintRule<any[], false>;
|
90
91
|
'selection-set-depth': import("..").GraphQLESLintRule<{
|
91
92
|
ignore?: string[];
|
92
93
|
maxDepth: number;
|