Linter rulesGraphQLrelay-arguments

relay-arguments

Since 0.9.0

This rule checks that fields returning connections take the pagination arguments of the Relay Cursor Connections specification.

Rule Details

Forward pagination takes first: Int and after (String or a scalar), backward pagination last: Int and before. By default both pairs are required.

Configuration

The configuration block is an object with the includeBoth property: whether both pairs of arguments are required (true by default) or one is enough.

version: "1.0"
commands:
  lint:
    graphql:
      rules:
        relay-arguments: [error, { includeBoth: false }]

The rule can be disabled for a node and everything nested in it with an # apigenie-lint-disable relay-arguments comment on the node, or for a whole file with the comment at the top of the file, separated from the first definition by a blank line. It applies to definitions.

Examples

Good.

type Query {
  users(first: Int, after: String, last: Int, before: String): UserConnection
}
interface Node { id: ID! }
type User implements Node { id: ID! }
type UserConnection { edges: [UserEdge], pageInfo: PageInfo! }
type UserEdge { node: User, cursor: String! }
type PageInfo {
  hasNextPage: Boolean!
  hasPreviousPage: Boolean!
  startCursor: String
  endCursor: String
}

Bad. The linter reports Field 'Query.users' returns a connection and should take the arguments first: Int, after: String, last: Int and before: String.

type Query { users: UserConnection }

Related rules

Further reading