rover icon indicating copy to clipboard operation
rover copied to clipboard

Offline `rover fields-usage` command

Open martinbonnin opened this issue 3 years ago • 2 comments

Description

To get a better understanding of how the schema is used, it would be useful to have a command that checks a list of .graphql operation files against a schema

Example usage

> rover fields-usage schema.graphqls operation1.graphql operation2.graphql ... operationN.graphql
type Query {
  hero (3)
  search (8)
}

type Character {
  name (3)
  email (2)
  appearsIn (0)
}

[...]

Where the output is the different schema types annotated with their respective usage count.

This could be run in CI to monitor the schema usage across different clients and for an example detect unused fields so that they can be scheduled for deprecation. Or together with schema checks to make sure a currently used field is never deleted.

martinbonnin avatar Apr 12 '21 13:04 martinbonnin

I think that it might also be useful to be able to output a report with the usages locations, but I am not sure what would be a good format for this output.

eduardb avatar Apr 13 '21 08:04 eduardb

Makes sense. Maybe aim for json as an output then? And store the path of all usages?

[
  {
    "name": "Query",
    "fields": {
      "hero": [
        "GetCharacterQuery.hero"
      ]
    }
  },
  {
    "name": "Character",
    "fields": {
      "name": [
        "GetCharacterQuery.hero.name",
        "GetCharacterQuery.hero.friends.name",
        "GetCharacterQuery.search.name"
      ],
      "appearsIn": []
    }
  }
]

martinbonnin avatar Apr 13 '21 08:04 martinbonnin