@graphql-eslint/eslint-plugin 3.14.0-alpha-20221222170519-5410a68 → 3.14.0-alpha-20221222175319-991733a

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,6 +19,7 @@ exports.default = {
19
19
  '@graphql-eslint/require-deprecation-date': 'error',
20
20
  '@graphql-eslint/require-field-of-type-query-in-mutation-result': 'error',
21
21
  '@graphql-eslint/require-nullable-fields-with-oneof': 'error',
22
+ '@graphql-eslint/require-type-pattern-with-oneof': 'error',
22
23
  },
23
24
  };
24
25
  module.exports = exports.default;
@@ -31,6 +31,7 @@ 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
33
  const require_nullable_fields_with_oneof_1 = require("./require-nullable-fields-with-oneof");
34
+ const require_type_pattern_with_oneof_1 = require("./require-type-pattern-with-oneof");
34
35
  const selection_set_depth_1 = require("./selection-set-depth");
35
36
  const strict_id_in_types_1 = require("./strict-id-in-types");
36
37
  const unique_fragment_name_1 = require("./unique-fragment-name");
@@ -63,6 +64,7 @@ exports.rules = {
63
64
  'require-field-of-type-query-in-mutation-result': require_field_of_type_query_in_mutation_result_1.rule,
64
65
  'require-id-when-available': require_id_when_available_1.rule,
65
66
  'require-nullable-fields-with-oneof': require_nullable_fields_with_oneof_1.rule,
67
+ 'require-type-pattern-with-oneof': require_type_pattern_with_oneof_1.rule,
66
68
  'selection-set-depth': selection_set_depth_1.rule,
67
69
  'strict-id-in-types': strict_id_in_types_1.rule,
68
70
  'unique-fragment-name': unique_fragment_name_1.rule,
@@ -38,15 +38,15 @@ exports.rule = {
38
38
  },
39
39
  create(context) {
40
40
  return {
41
- 'Directive[name.value=oneOf]'(node) {
41
+ 'Directive[name.value=oneOf]'({ parent, }) {
42
42
  const isTypeOrInput = [
43
43
  graphql_1.Kind.OBJECT_TYPE_DEFINITION,
44
44
  graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION,
45
- ].includes(node.parent.kind);
45
+ ].includes(parent.kind);
46
46
  if (!isTypeOrInput) {
47
47
  return;
48
48
  }
49
- for (const field of node.parent.fields) {
49
+ for (const field of parent.fields) {
50
50
  if (field.gqlType.kind === graphql_1.Kind.NON_NULL_TYPE) {
51
51
  context.report({
52
52
  node: field.name,
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rule = void 0;
4
+ const RULE_ID = 'require-type-pattern-with-oneof';
5
+ exports.rule = {
6
+ meta: {
7
+ type: 'suggestion',
8
+ docs: {
9
+ category: 'Schema',
10
+ description: 'Enforce types with `@oneOf` directive have `error` and `ok` fields.',
11
+ url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
12
+ examples: [
13
+ {
14
+ title: 'Correct',
15
+ code: /* GraphQL */ `
16
+ type Mutation {
17
+ doSomething: DoSomethingMutationResult!
18
+ }
19
+
20
+ interface Error {
21
+ message: String!
22
+ }
23
+
24
+ type DoSomethingMutationResult @oneOf {
25
+ ok: DoSomethingSuccess
26
+ error: Error
27
+ }
28
+
29
+ type DoSomethingSuccess {
30
+ # ...
31
+ }
32
+ `,
33
+ },
34
+ ],
35
+ },
36
+ messages: {
37
+ [RULE_ID]: 'Type `{{typeName}}` should have `{{fieldName}}` field.',
38
+ },
39
+ schema: [],
40
+ },
41
+ create(context) {
42
+ return {
43
+ 'Directive[name.value=oneOf][parent.kind=ObjectTypeDefinition]'({ parent, }) {
44
+ const requiredFields = ['error', 'ok'];
45
+ for (const fieldName of requiredFields) {
46
+ if (!parent.fields.some(field => field.name.value === fieldName)) {
47
+ context.report({
48
+ node: parent.name,
49
+ messageId: RULE_ID,
50
+ data: {
51
+ typeName: parent.name.value,
52
+ fieldName,
53
+ },
54
+ });
55
+ }
56
+ }
57
+ },
58
+ };
59
+ },
60
+ };
package/docs/README.md CHANGED
@@ -59,6 +59,7 @@ Name            &nbs
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
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][]|📄|🚀|
62
+ [require-type-pattern-with-oneof](rules/require-type-pattern-with-oneof.md)|Enforce types with `@oneOf` directive have `error` and `ok` fields.|![all][]|📄|🚀|
62
63
  [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][]|đŸ“Ļ|🔮|💡
63
64
  [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][]|đŸ“Ļ|🚀|💡
64
65
  [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,39 @@
1
+ # `require-type-pattern-with-oneof`
2
+
3
+ - Category: `Schema`
4
+ - Rule name: `@graphql-eslint/require-type-pattern-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
+ Enforce types with `@oneOf` directive have `error` and `ok` fields.
10
+
11
+ ## Usage Examples
12
+
13
+ ### Correct
14
+
15
+ ```graphql
16
+ # eslint @graphql-eslint/require-type-pattern-with-oneof: 'error'
17
+
18
+ type Mutation {
19
+ doSomething: DoSomethingMutationResult!
20
+ }
21
+
22
+ interface Error {
23
+ message: String!
24
+ }
25
+
26
+ type DoSomethingMutationResult @oneOf {
27
+ ok: DoSomethingSuccess
28
+ error: Error
29
+ }
30
+
31
+ type DoSomethingSuccess {
32
+ # ...
33
+ }
34
+ ```
35
+
36
+ ## Resources
37
+
38
+ - [Rule source](../../packages/plugin/src/rules/require-type-pattern-with-oneof.ts)
39
+ - [Test source](../../packages/plugin/tests/require-type-pattern-with-oneof.spec.ts)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "3.14.0-alpha-20221222170519-5410a68",
3
+ "version": "3.14.0-alpha-20221222175319-991733a",
4
4
  "description": "GraphQL plugin for ESLint",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -58,6 +58,7 @@ export declare const configs: {
58
58
  '@graphql-eslint/require-deprecation-date': string;
59
59
  '@graphql-eslint/require-field-of-type-query-in-mutation-result': string;
60
60
  '@graphql-eslint/require-nullable-fields-with-oneof': string;
61
+ '@graphql-eslint/require-type-pattern-with-oneof': string;
61
62
  };
62
63
  };
63
64
  'operations-recommended': {
@@ -58,6 +58,7 @@ export declare const configs: {
58
58
  '@graphql-eslint/require-deprecation-date': string;
59
59
  '@graphql-eslint/require-field-of-type-query-in-mutation-result': string;
60
60
  '@graphql-eslint/require-nullable-fields-with-oneof': string;
61
+ '@graphql-eslint/require-type-pattern-with-oneof': string;
61
62
  };
62
63
  };
63
64
  'operations-recommended': {
@@ -11,6 +11,7 @@ declare const _default: {
11
11
  '@graphql-eslint/require-deprecation-date': string;
12
12
  '@graphql-eslint/require-field-of-type-query-in-mutation-result': string;
13
13
  '@graphql-eslint/require-nullable-fields-with-oneof': string;
14
+ '@graphql-eslint/require-type-pattern-with-oneof': string;
14
15
  };
15
16
  };
16
17
  export default _default;
@@ -11,6 +11,7 @@ declare const _default: {
11
11
  '@graphql-eslint/require-deprecation-date': string;
12
12
  '@graphql-eslint/require-field-of-type-query-in-mutation-result': string;
13
13
  '@graphql-eslint/require-nullable-fields-with-oneof': string;
14
+ '@graphql-eslint/require-type-pattern-with-oneof': string;
14
15
  };
15
16
  };
16
17
  export default _default;
@@ -88,6 +88,7 @@ export declare const rules: {
88
88
  fieldName?: string | string[];
89
89
  }[], true>;
90
90
  'require-nullable-fields-with-oneof': import("..").GraphQLESLintRule<any[], false>;
91
+ 'require-type-pattern-with-oneof': import("..").GraphQLESLintRule<any[], false>;
91
92
  'selection-set-depth': import("..").GraphQLESLintRule<{
92
93
  ignore?: string[];
93
94
  maxDepth: number;
@@ -88,6 +88,7 @@ export declare const rules: {
88
88
  fieldName?: string | string[];
89
89
  }[], true>;
90
90
  'require-nullable-fields-with-oneof': import("..").GraphQLESLintRule<any[], false>;
91
+ 'require-type-pattern-with-oneof': import("..").GraphQLESLintRule<any[], false>;
91
92
  'selection-set-depth': import("..").GraphQLESLintRule<{
92
93
  ignore?: string[];
93
94
  maxDepth: number;
@@ -0,0 +1,2 @@
1
+ import { GraphQLESLintRule } from '../types';
2
+ export declare const rule: GraphQLESLintRule;
@@ -0,0 +1,2 @@
1
+ import { GraphQLESLintRule } from '../types';
2
+ export declare const rule: GraphQLESLintRule;