# relay-edge-types

Source: https://apigenie.pl/docs/linter/graphql/rules/relay-edge-types

This rule checks that the edge types of connections follow the Relay Cursor Connections specification.

## Rule Details

The edge types returned by the `edges` field of connection types are object types with a `node` field that is not a list and a `cursor` field of type String or a scalar.

## Configuration

The configuration block is an object with the boolean properties:

- `withEdgeSuffix`: edge type names end with `Edge`; `true` by default
- `shouldImplementNode`: the object types of nodes implement the `Node` interface; `true` by
  default
- `listTypeCanWrapOnlyEdgeType`: the list fields of connection types return edge types; `false`
  by default

```yaml
version: "1.0"
commands:
  lint:
    graphql:
      rules:
        relay-edge-types: [error, { shouldImplementNode: false }]
```

The rule can be disabled for a node and everything nested in it with an `# apigenie-lint-disable relay-edge-types` 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**.

```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 `Edge type 'UserEdge' should have a 'node' field that is not a list`.

```graphql
type UserConnection { edges: [UserEdge], pageInfo: PageInfo! }
type UserEdge { node: [User] }
```
