Skip to content

Commit 36d5334

Browse files
author
Dimitri POSTOLOV
authored
fix: ignore arguments in no-scalar-result-type-on-mutation rule (#797)
1 parent 5a259ce commit 36d5334

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

.changeset/unlucky-buses-eat.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 `no-scalar-result-type-on-mutation` rule

packages/plugin/src/rules/no-scalar-result-type-on-mutation.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Kind, FieldDefinitionNode, isScalarType } from 'graphql';
1+
import { Kind, isScalarType, NameNode } from 'graphql';
22
import { getLocation, requireGraphQLSchemaFromContext } from '../utils';
33
import { GraphQLESLintRule } from '../types';
44
import { GraphQLESTreeNode } from '../estree-parser';
@@ -40,14 +40,12 @@ const rule: GraphQLESLintRule = {
4040
}
4141
const selector = [
4242
`:matches(${Kind.OBJECT_TYPE_DEFINITION}, ${Kind.OBJECT_TYPE_EXTENSION})[name.value=${mutationType.name}]`,
43-
'>',
44-
Kind.FIELD_DEFINITION,
45-
Kind.NAMED_TYPE,
43+
`> ${Kind.FIELD_DEFINITION} > .gqlType ${Kind.NAME}`,
4644
].join(' ');
4745

4846
return {
49-
[selector](node: GraphQLESTreeNode<FieldDefinitionNode>) {
50-
const typeName = node.name.value;
47+
[selector](node: GraphQLESTreeNode<NameNode>) {
48+
const typeName = node.value;
5149
const graphQLType = schema.getType(typeName);
5250
if (isScalarType(graphQLType)) {
5351
context.report({

packages/plugin/tests/__snapshots__/no-scalar-result-type-on-mutation.spec.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
exports[` 1`] = `
44
1 |
55
2 | type Mutation {
6-
> 3 | createUser: Boolean
7-
| ^^^^^^^ Unexpected scalar result type "Boolean"
6+
> 3 | createUser(a: ID, b: ID!, c: [ID]!, d: [ID!]!): Boolean
7+
| ^^^^^^^ Unexpected scalar result type "Boolean"
88
4 | }
99
5 |
1010
`;

packages/plugin/tests/no-scalar-result-type-on-mutation.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ ruleTester.runGraphQLTests('no-scalar-result-type-on-mutation', rule, {
4040
],
4141
invalid: [
4242
{
43+
name: 'should ignore arguments',
4344
...useSchema(/* GraphQL */ `
4445
type Mutation {
45-
createUser: Boolean
46+
createUser(a: ID, b: ID!, c: [ID]!, d: [ID!]!): Boolean
4647
}
4748
`),
4849
errors: [{ message: 'Unexpected scalar result type "Boolean"' }],

0 commit comments

Comments
 (0)