# relay-arguments

Source: https://api-genie.dev/docs/linter/graphql/rules/relay-arguments

A rule of the GraphQL linter, which reads GraphQL schemas and operations. Since 0.9.0. In the rulesets: All at error, Relay at error.

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.

The rule applies to definitions. An `# apigenie-lint-disable relay-arguments` comment on a node
turns it off for the node and everything nested in it; at the top of the file, separated from the
first definition by a blank line, the comment turns it off for the whole file.

## 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.

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

## Examples

**Good**.

```graphql
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`.

```graphql
type Query { users: UserConnection }
```
