# ViewConnections

## Overview

All collections in the Finale GraphQL API are accessed via **ViewConnection** queries. This is a consistent pattern across all data types.

## Naming Convention

For any collection `{name}`, the GraphQL query is `{name}ViewConnection`.

**Examples:**

- `product` → `productViewConnection`
- `order` → `orderViewConnection`
- `location` → `locationViewConnection`

## Relay Connection Specification

ViewConnections follow the Relay connection specification, which provides:

1. **Pagination Support**: Cursor-based pagination with `first`, `last`, `after`, and `before` arguments
2. **Edges and Nodes**: Results are wrapped in `edges` containing `node` objects
3. **Page Info**: Metadata about pagination state via `pageInfo`

## Structure

GraphQL

```graphql
{
  {collection}ViewConnection(
    first: Int
    last: Int
    after: String
    before: String
    sort: [SortInput]
    # Collection-specific filters
  ) {
    edges {
      node {
        # Fields from the collection
      }
      cursor
    }
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
    strategy  # Query execution strategy used
  }
}
```

## Example Query

GraphQL

```graphql
query {
  productViewConnection(first: 10) {
    edges {
      node {
        productId
        sku
        description
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}
```

## Why ViewConnections?

This pattern provides:

- Consistent interface across all collections
- Built-in pagination support
- Efficient cursor-based navigation
- Standard way to handle large datasets
- Integration with Relay and other GraphQL clients
