Graphql-ruby: Rubocop extension

Created on 4 Nov 2016  路  7Comments  路  Source: rmosolgo/graphql-ruby

It would be interesting to provide a set of Rubocop cops in the repo that people can optionally enable in their own rubocop.yml to do checks on their schema.

Some example checks:

  • Naming conventions for Mutations and other parts of the Schema
  • Relay conventions

    • All mutations should include a clientMutationId field

    • Mutations that remove nodes should include a deletedId field

    • Single input argument on mutations

  • Detect breaking schema changes by comparing checked-in IDL with current commits IDL
  • Detect N+1 (if possible) or provide tools to enable people to check this

Feel free to add more ideas.

cc @xuorig @Willianvdv @brandonblack

Edit: Rubocop might not be a silver bullet here since in some cases we might have to run the Ruby code, for instance detecting N+1s with static code analysis might not be feasible.

Most helpful comment

All 7 comments

cc @gjtorikian @josh

Nice. I started working on some graphql-client specific cops already. https://github.com/github/graphql-client/tree/master/lib/rubocop/cop/graphql Would be rad to have some basic ones here as well.

We don't have a cop for this (we use tests) but "has a description" would be grand, as well as conventions for resolve styling (-> {...} vs do ... end).

What do you think about a linter that checks if the name of a mutation starts with capital letter?
So:

# Good
AddCommentMutation = GraphQL::Relay::Mutation.define do
  name "AddComment"
end

# Bad
AddCommentMutation = GraphQL::Relay::Mutation.define do
  name "addComment"
end

I have no plans to work on this but I would welcome suggestions here or in another issue if someone else wants to do it!

I've implemented some _graphql-ruby_ checks in rubocop-graphql, would be happy to hear back ideas and feedback

Was this page helpful?
0 / 5 - 0 ratings