Lint GraphQL queries with `eslint-plugin-graphql`
GraphQL queries written on the client-side are currently not validated in our build process. This can lead to bugs e.g.:
- querying for something that doesn't exist
- duplicate query definitions
We should be able to leverage eslint-plugin-graphql to lint our .graphql files against our schema.
Why?
The addition of such a set of tooling would:
- boost productivity of anyone writing GraphQL queries in
gitlab-org/gitlab - reduce code review duration when
.graphqlfiles are involved - reduce occurrence of bugs
How?
@tomquirk briefly explored this in !33242 (closed), however came across some issues listed in the section below
Issues that need to be resolved
-
Some of our queries contain a @clientdirective (e.g. https://gitlab.com/gitlab-org/gitlab/blob/c97c456dfa878acdc755f97326d40f77d5f4bee4/app/assets/javascripts/design_management/graphql/queries/active_discussion.query.graphql#L4), andeslint-plugin-graphqlcan't seem to handle this case out of the box. -
eslint-plugin-graphqldoesn't seem to catch duplicate query definitions, whereas the Apollo extension for VS Code does
Edited by Tom Quirk