> For the complete documentation index, see [llms.txt](https://superd001.gitbook.io/autorelay/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://superd001.gitbook.io/autorelay/fix-abstract-resolver/pagination-1/extending-pageinfo-connection.md).

# Extending PageInfo / Connection

## Bi-directional PageInfo

The Relay specs by default does not compute hasPreviousPage when paging forwards, and does not compute hasNextPage when paging forwards ([see this issue for details](https://github.com/graphql/graphql-relay-js/issues/58)) as it may be expensive to compute them. However, as many usecases of AutoRelay (mainly while fetching from a main database with limit/offset) do provide a very inexpensive way to compute that data, a `biDirectionalPageInfo` option has been created to allow calculating both those arguments from the first/last arguments and the entity count returned.

This option can be set globally or per query/field resolver

*globally*

```typescript
new AutoRelayConfig({ pagination: { biDirectionalPageInfo: true } })
```

*per query*

```typescript
@RelayedQuery(() => MyEntity, { biDirectionalPageInfo: true })
public async myEntities() {

}
```

## Adding your own logic

AutoRelay allows extending `PageInfo` and `Connection` Objects with your own base classes. This can be useful for augmenting the Relay spec. The following example shows how to add a "totalCount" field containing the total number of items matching a paginated query

*src/base-connection.ts*

```typescript
import { RelayNbOfItems } from 'auto-relay'

@ObjectType({ abstract: true })
export class BaseConnection {

  @Field(() => Int)
  public totalCount(
    @RelayNbOfItems() nbOfItem: number
  ): number {
    return nbOfItem;
  }

}
```

*src/index.ts*

```typescript
new AutoRelayConfig({ extends: { connection: () => BaseConnection } })
```

this will result in all Connection objects being augmented with the `totalCount` field
