Skip to content

Commit 32ec2cb

Browse files
author
Dimitri POSTOLOV
authored
fix: ignore arguments in require-field-of-type-query-in-mutation-result rule (#799)
1 parent 36d5334 commit 32ec2cb

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

.changeset/rotten-eggs-rest.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
fix: ignore arguments in `require-field-of-type-query-in-mutation-result` rule

packages/plugin/src/rules/require-field-of-type-query-in-mutation-result.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Kind, FieldDefinitionNode, isObjectType } from 'graphql';
1+
import { Kind, isObjectType, NameNode } from 'graphql';
22
import { requireGraphQLSchemaFromContext, getTypeName, getLocation } from '../utils';
33
import { GraphQLESLintRule } from '../types';
44
import { GraphQLESTreeNode } from '../estree-parser';
@@ -56,14 +56,12 @@ const rule: GraphQLESLintRule = {
5656
}
5757
const selector = [
5858
`:matches(${Kind.OBJECT_TYPE_DEFINITION}, ${Kind.OBJECT_TYPE_EXTENSION})[name.value=${mutationType.name}]`,
59-
'>',
60-
Kind.FIELD_DEFINITION,
61-
Kind.NAMED_TYPE,
59+
`> ${Kind.FIELD_DEFINITION} > .gqlType ${Kind.NAME}`,
6260
].join(' ');
6361

6462
return {
65-
[selector](node: GraphQLESTreeNode<FieldDefinitionNode>) {
66-
const typeName = node.name.value;
63+
[selector](node: GraphQLESTreeNode<NameNode>) {
64+
const typeName = node.value;
6765
const graphQLType = schema.getType(typeName);
6866

6967
if (isObjectType(graphQLType)) {
@@ -72,7 +70,7 @@ const rule: GraphQLESLintRule = {
7270
if (!hasQueryType) {
7371
context.report({
7472
loc: getLocation(node.loc, typeName),
75-
message: `Mutation result type "${graphQLType.name}" must contain field of type "${queryType.name}".`,
73+
message: `Mutation result type "${graphQLType.name}" must contain field of type "${queryType.name}"`,
7674
});
7775
}
7876
}

packages/plugin/tests/__snapshots__/require-field-of-type-query-in-mutation-result.spec.ts.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ exports[` 1`] = `
44
1 |
55
2 | type Query
66
3 | type Mutation {
7-
> 4 | createUser: User!
8-
| ^^^^ Mutation result type "User" must contain field of type "Query".
7+
> 4 | createUser(a: User, b: User!, c: [User], d: [User]!, e: [User!]!): User
8+
| ^^^^ Mutation result type "User" must contain field of type "Query"
99
5 | }
1010
6 |
1111
`;
@@ -17,7 +17,7 @@ exports[` 2`] = `
1717
4 |
1818
5 | extend type Mutation {
1919
> 6 | createUser: User!
20-
| ^^^^ Mutation result type "User" must contain field of type "Query".
20+
| ^^^^ Mutation result type "User" must contain field of type "Query"
2121
7 | }
2222
8 |
2323
`;
@@ -26,8 +26,8 @@ exports[` 3`] = `
2626
1 |
2727
2 | type RootQuery
2828
3 | type RootMutation {
29-
> 4 | createUser: User!
30-
| ^^^^ Mutation result type "User" must contain field of type "RootQuery".
29+
> 4 | createUser: [User]
30+
| ^^^^ Mutation result type "User" must contain field of type "RootQuery"
3131
5 | }
3232
6 |
3333
7 | schema {
@@ -42,8 +42,8 @@ exports[` 4`] = `
4242
2 | type RootQuery
4343
3 | type RootMutation
4444
4 | extend type RootMutation {
45-
> 5 | createUser: User!
46-
| ^^^^ Mutation result type "User" must contain field of type "RootQuery".
45+
> 5 | createUser: [User!]!
46+
| ^^^^ Mutation result type "User" must contain field of type "RootQuery"
4747
6 | }
4848
7 |
4949
8 | schema {

packages/plugin/tests/require-field-of-type-query-in-mutation-result.spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ ruleTester.runGraphQLTests('require-field-of-type-query-in-mutation-result', rul
6161
],
6262
invalid: [
6363
{
64+
name: 'should ignore arguments',
6465
...useSchema(/* GraphQL */ `
6566
type Query
6667
type Mutation {
67-
createUser: User!
68+
createUser(a: User, b: User!, c: [User], d: [User]!, e: [User!]!): User
6869
}
6970
`),
70-
errors: [{ message: 'Mutation result type "User" must contain field of type "Query".' }],
71+
errors: [{ message: 'Mutation result type "User" must contain field of type "Query"' }],
7172
},
7273
{
7374
...useSchema(/* GraphQL */ `
@@ -78,36 +79,36 @@ ruleTester.runGraphQLTests('require-field-of-type-query-in-mutation-result', rul
7879
createUser: User!
7980
}
8081
`),
81-
errors: [{ message: 'Mutation result type "User" must contain field of type "Query".' }],
82+
errors: [{ message: 'Mutation result type "User" must contain field of type "Query"' }],
8283
},
8384
{
8485
...useSchema(/* GraphQL */ `
8586
type RootQuery
8687
type RootMutation {
87-
createUser: User!
88+
createUser: [User]
8889
}
8990
9091
schema {
9192
mutation: RootMutation
9293
query: RootQuery
9394
}
9495
`),
95-
errors: [{ message: 'Mutation result type "User" must contain field of type "RootQuery".' }],
96+
errors: [{ message: 'Mutation result type "User" must contain field of type "RootQuery"' }],
9697
},
9798
{
9899
...useSchema(/* GraphQL */ `
99100
type RootQuery
100101
type RootMutation
101102
extend type RootMutation {
102-
createUser: User!
103+
createUser: [User!]!
103104
}
104105
105106
schema {
106107
mutation: RootMutation
107108
query: RootQuery
108109
}
109110
`),
110-
errors: [{ message: 'Mutation result type "User" must contain field of type "RootQuery".' }],
111+
errors: [{ message: 'Mutation result type "User" must contain field of type "RootQuery"' }],
111112
},
112113
],
113114
});

0 commit comments

Comments
 (0)