Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rotten-eggs-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': patch
---

fix: ignore arguments in `require-field-of-type-query-in-mutation-result` rule
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Kind, FieldDefinitionNode, isObjectType } from 'graphql';
import { Kind, isObjectType, NameNode } from 'graphql';
import { requireGraphQLSchemaFromContext, getTypeName, getLocation } from '../utils';
import { GraphQLESLintRule } from '../types';
import { GraphQLESTreeNode } from '../estree-parser';
Expand Down Expand Up @@ -56,14 +56,12 @@ const rule: GraphQLESLintRule = {
}
const selector = [
`:matches(${Kind.OBJECT_TYPE_DEFINITION}, ${Kind.OBJECT_TYPE_EXTENSION})[name.value=${mutationType.name}]`,
'>',
Kind.FIELD_DEFINITION,
Kind.NAMED_TYPE,
`> ${Kind.FIELD_DEFINITION} > .gqlType ${Kind.NAME}`,
].join(' ');

return {
[selector](node: GraphQLESTreeNode<FieldDefinitionNode>) {
const typeName = node.name.value;
[selector](node: GraphQLESTreeNode<NameNode>) {
const typeName = node.value;
const graphQLType = schema.getType(typeName);

if (isObjectType(graphQLType)) {
Expand All @@ -72,7 +70,7 @@ const rule: GraphQLESLintRule = {
if (!hasQueryType) {
context.report({
loc: getLocation(node.loc, typeName),
message: `Mutation result type "${graphQLType.name}" must contain field of type "${queryType.name}".`,
message: `Mutation result type "${graphQLType.name}" must contain field of type "${queryType.name}"`,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ exports[` 1`] = `
1 |
2 | type Query
3 | type Mutation {
> 4 | createUser: User!
| ^^^^ Mutation result type "User" must contain field of type "Query".
> 4 | createUser(a: User, b: User!, c: [User], d: [User]!, e: [User!]!): User
| ^^^^ Mutation result type "User" must contain field of type "Query"
5 | }
6 |
`;
Expand All @@ -17,7 +17,7 @@ exports[` 2`] = `
4 |
5 | extend type Mutation {
> 6 | createUser: User!
| ^^^^ Mutation result type "User" must contain field of type "Query".
| ^^^^ Mutation result type "User" must contain field of type "Query"
7 | }
8 |
`;
Expand All @@ -26,8 +26,8 @@ exports[` 3`] = `
1 |
2 | type RootQuery
3 | type RootMutation {
> 4 | createUser: User!
| ^^^^ Mutation result type "User" must contain field of type "RootQuery".
> 4 | createUser: [User]
| ^^^^ Mutation result type "User" must contain field of type "RootQuery"
5 | }
6 |
7 | schema {
Expand All @@ -42,8 +42,8 @@ exports[` 4`] = `
2 | type RootQuery
3 | type RootMutation
4 | extend type RootMutation {
> 5 | createUser: User!
| ^^^^ Mutation result type "User" must contain field of type "RootQuery".
> 5 | createUser: [User!]!
| ^^^^ Mutation result type "User" must contain field of type "RootQuery"
6 | }
7 |
8 | schema {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ ruleTester.runGraphQLTests('require-field-of-type-query-in-mutation-result', rul
],
invalid: [
{
name: 'should ignore arguments',
...useSchema(/* GraphQL */ `
type Query
type Mutation {
createUser: User!
createUser(a: User, b: User!, c: [User], d: [User]!, e: [User!]!): User
}
`),
errors: [{ message: 'Mutation result type "User" must contain field of type "Query".' }],
errors: [{ message: 'Mutation result type "User" must contain field of type "Query"' }],
},
{
...useSchema(/* GraphQL */ `
Expand All @@ -78,36 +79,36 @@ ruleTester.runGraphQLTests('require-field-of-type-query-in-mutation-result', rul
createUser: User!
}
`),
errors: [{ message: 'Mutation result type "User" must contain field of type "Query".' }],
errors: [{ message: 'Mutation result type "User" must contain field of type "Query"' }],
},
{
...useSchema(/* GraphQL */ `
type RootQuery
type RootMutation {
createUser: User!
createUser: [User]
}

schema {
mutation: RootMutation
query: RootQuery
}
`),
errors: [{ message: 'Mutation result type "User" must contain field of type "RootQuery".' }],
errors: [{ message: 'Mutation result type "User" must contain field of type "RootQuery"' }],
},
{
...useSchema(/* GraphQL */ `
type RootQuery
type RootMutation
extend type RootMutation {
createUser: User!
createUser: [User!]!
}

schema {
mutation: RootMutation
query: RootQuery
}
`),
errors: [{ message: 'Mutation result type "User" must contain field of type "RootQuery".' }],
errors: [{ message: 'Mutation result type "User" must contain field of type "RootQuery"' }],
},
],
});