graphql-eslint icon indicating copy to clipboard operation
graphql-eslint copied to clipboard

New rule: Duplicate fields in schema

Open tvvignesh opened this issue 4 years ago • 1 comments

Is your feature request related to a problem? Please describe.

When I duplicate fields in my schema and use codegen, I get errors like these: image

Looks like this error is coming in from graphql-js and not codegen itself. But I don't find a rule for duplicated fields (in schema) as a rule. There is a rule for documents though.

Describe the solution you'd like Adding a new rule for duplicated fields in schema in graphql-eslint can address this.

Describe alternatives you've considered Alternative currently is to rely on codegen for throwing errors like these, but this can be captured in eslint itself.

tvvignesh avatar Oct 06 '21 05:10 tvvignesh

Hi @tvvignesh, currently buildSchema from graphql throws an error when find a duplicated field for ObjectTypeDefinition, InterfaceTypeDefinition, EnumTypeDefinition, InputObjectTypeDefinition kinds and same for their extensions ObjectTypeExtension... etc. I agree with you, we can validate duplication fields before building our schema, the new rule or new option for the existing rule avoid-duplicate-fields will be added 😉

UPDATE: We have already rules from graphql-js that checks for duplication fields, like unique-field-definition-names, unique-input-field-names, unique-enum-value-names and they work not as expected, when you have split schema for multiple files, I'll try to fix this

dimaMachina avatar Oct 14 '21 18:10 dimaMachina