Skip to content

Ask HN: Is it GraphQL best practice to limit root query types?

2 pointsgeekjockdiscuss
On HN

I was looking at the GitHub GraphQL API (https://developer.github.com/v4/query) and noticed that they only expose a few root query types.

For example, to get a pull request you must use the `repository` Query type and access a pull request through the `Repository` object fields.

  {
    repository(name: 'test') {
      pull_request(number: 2) {
        title
      }
    }
  }
You can't just access a pull request by ID via a root query type:
  {
    pull_request(id: 12345) {
      title
    }
  }
Is this a recommended practice? Is there an argument for limiting root query types in favor of using nested object types to keep the schema cleaner?

Comments

No comments yet.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.