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

Making it possible to require all of the given field names on `require-id-when-available`

Open ikesyo opened this issue 2 years ago • 5 comments

Is your feature request related to a problem? Please describe. When using the require-id-when-available rule with passing an array of field names, the rule passes if one of the field names exists in the selection set. I want that all of them should exist in the selection set (all given fields are required if the fields are defined on a type).

Describe the solution you'd like

Add configuration option which treating the given fields as all required.

Describe alternatives you've considered

Additional context

Migration from apollographql/eslint-plugin-graphql's required-fields rule (migration to graphql-eslint is suggested in the README). That rule's behavior is desirable for us.

  • https://github.com/apollographql/eslint-plugin-graphql#required-fields-validation-rule
  • https://github.com/apollographql/eslint-plugin-graphql/blob/64c524cd6607358803d5fcb7cead0a383a125ccb/src/customGraphQLValidationRules.js#L32

ikesyo avatar May 24 '22 07:05 ikesyo

Not working with error Rule require-id-when-availablerequiresparserOptions.operations, my config { "files": [".ts"], "processor": "@graphql-eslint/graphql" }, { "files": [".graphql"], "extends": "plugin:@graphql-eslint/operations-recommended", "rules": { "@graphql-eslint/known-type-names": "error" }, "parserOptions": { "operations": "./src/**/*.graphql" ], "schema": "./remote-schema.graphql" } }`

milashkaJason avatar Jun 14 '22 09:06 milashkaJason

Hi @milashkaJason, does your issue related to require-id-when-available? Can you give more context or maybe make a reproduction repo?

dimaMachina avatar Jun 16 '22 12:06 dimaMachina

I got the same issue and I finally get it work by disabling the rules

'@graphql-eslint/require-id-when-available': 'off',
'@graphql-eslint/no-unused-fragments': 'off',

francois-spectre avatar Jun 20 '22 13:06 francois-spectre

The problem was in the parameter parserOptions: { operations}, because it interfered .graphqlconfig

milashkaJason avatar Jun 20 '22 13:06 milashkaJason

I'm posting the reproduction here instead of reopening https://github.com/dimaMachina/graphql-eslint/issues/1159. To reproduce, go to the playground and enter in operation.graphql:

# eslint @graphql-eslint/require-id-when-available: ["error", { fieldName: ["id", "__typename"] }]
query Q {
  posts {
    id
    title
  }
}

Or ["id", "createdAt"]. The code should be invalid, since only id is included in the selection and __typename/createdAt isn't.

alexeyr-ci avatar Jan 05 '24 07:01 alexeyr-ci