# Facility

## Overview

Facilities represent the physical and logical locations where inventory is stored or moved. They provide the structure for tracking where products are located, supporting everything from basic warehouse operations to multi-location inventory management. The system distinguishes between locations (warehouse-level) and sublocations (areas within warehouses).

Locations represent physical warehouses, stores, or storage sites. Each location is a separate physical space where inventory is held. Multi-location businesses use this to track inventory across different geographic sites - a distribution center in California, another in New York, a retail store in Texas. Each location's inventory is tracked separately, letting you see what's available at each site for fulfillment or transfer planning.

Sublocations represent specific areas within a location. These might be aisles, bins, shelves, or zones within a warehouse. By tracking inventory at the sublocation level, you achieve bin-level accuracy that supports efficient picking and putaway. Workers can be directed to exact bins, reducing search time and errors. Cycle counting can target specific sublocations, improving inventory accuracy without full warehouse counts.

The facility hierarchy is typically two levels - locations containing sublocations. A location might have dozens or hundreds of sublocations depending on warehouse size and complexity. This structure balances detailed tracking with manageable complexity. You can report at the location level for high-level visibility or at the sublocation level for operational precision.

Transit sublocations are special system-created areas representing goods in transit. When inventory is shipped from one location to another, it moves to a transit sublocation until it's received. This ensures inventory is always accounted for - it's never "lost" between locations. Transit tracking is automatic and provides visibility into in-transit stock for accurate available-to-promise calculations.

Facility status controls whether a location can be used. Active facilities accept new inventory transactions. Inactive facilities are retained for historical reporting but can't be used for new shipments or stock. This lets you phase out closed warehouses without losing historical data.

The control type indicates what kind of inventory tracking applies. Some facilities might track lot numbers, others serial numbers, others just quantities. This facility-level control supports different operational models in different parts of your business - tight serialized control in one location, simpler quantity tracking in another.

---

### GraphQL API

The `facility` collection provides access to facility data via the GraphQL API. All queries use the Relay connection specification with cursor-based pagination.

**Query Name:** `facilityViewConnection`

**Available Features:**

- Cursor-based pagination (first/last/after/before)
- 7 filter options
- 1 sortable field
- 1 relation to other collections

## Query Examples

### Basic Query

The `facility` collection is accessed via the `facilityViewConnection` query, which returns a Relay-style connection with pagination support.

GraphQL

```graphql
query {
  facilityViewConnection(first: 10) {
    edges {
      node {
        controlTypeId
        facilityUrl
        name
        parentFacilityUrl
        status
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}
```

### Pagination

Use cursor-based pagination to retrieve large datasets:

GraphQL

```graphql
# First page
query {
  facilityViewConnection(first: 50) {
    edges {
      node { controlTypeId }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}

# Subsequent pages
query {
  facilityViewConnection(first: 50, after: "cursor-from-previous-page") {
    edges {
      node { controlTypeId }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}
```

### Filtering

Apply filters to narrow results:

GraphQL

```graphql
query {
  facilityViewConnection(
    first: 10
    controlTypeId: "FACILITY_USER"
  ) {
    edges {
      node { controlTypeId }
    }
  }
}
```

### Sorting

Sort results by one or more fields:

GraphQL

```graphql
query {
  facilityViewConnection(
    first: 10
    sort: [{ field: "name", mode: "desc" }]
  ) {
    edges {
      node {
        controlTypeId
        name
      }
    }
  }
}
```

### Relations

Query related data:

GraphQL

```graphql
query {
  facilityViewConnection(first: 10) {
    edges {
      node {
        controlTypeId
        location {
          name
          facilityUrl
        }
      }
    }
  }
}
```

## Summary and Aggregation

This collection supports metrics aggregation through the `summary` field. You can calculate totals, averages, counts, and other aggregate values across filtered data.

**Note:** This collection does not support groupBy dimensions.

### Query Structure

GraphQL

```graphql
facilityViewConnection(filters...) {
  summary {
    errorCode
    errorMessage
    metrics {
      # Calculated metrics (see table below)
    }
  }
}
```

### Available Metrics

This collection provides 1 metric that can be aggregated:

| Metric | Parameters | Description |
| --- | --- | --- |
| `count` | None | Count of items in the result set |

**Common Parameters:**

- `operator` - Aggregation function: `sum`, `mean`, `min`, `max`
- `transform` - Mathematical transformation: `abs`
- `dateRange` - Filter to specific date range
- `facilityUrlList` - Filter to specific facilities

### Examples

#### Example 1: Total facility Metrics

Calculate aggregate metrics across all facility records:

GraphQL

```graphql
query {
  facilityViewConnection(first: 1) {
    summary {
      errorCode
      errorMessage
      metrics {
        totalCount: count
      }
    }
  }
}
```

Expected result structure:

JSON

```json
{
  "data": {
    "facilityViewConnection": {
      "summary": {
        "errorCode": null,
        "errorMessage": null,
        "metrics": {
          "totalCount": [1523]
        }
      }
    }
  }
}
```

## Fields

This collection has 6 fields:

- 3 simple fields
- 3 enum fields (with predefined values)
- 0 parameterized fields (accept query options)

### Simple Fields

#### `facilityUrl`

The unique identifier for the facility.

**Label:** Facility Url  
**Sortable:** No

#### `name`

The unique identifier and display name for a facility.

**Label:** Name  
**Sortable:** Yes

#### `parentFacilityUrl`

References the parent facility for sublocations in a hierarchical facility structure.

**Label:** Parent facility url  
**Sortable:** No

### Enum Fields

#### `controlTypeId`

Distinguishes between user-managed facilities and system-managed facilities.

**Label:** Control type  
**Sortable:** No  
**Possible Values:**
- `FACILITY_USER` - User
- `FACILITY_SYSTEM` - System

#### `status`

Indicates whether a facility is active or inactive.

**Label:** Status  
**Sortable:** No  
**Possible Values:**
- `FACILITY_ACTIVE` - Active
- `FACILITY_INACTIVE` - Inactive

#### `type`

Indicates whether the facility is a top-level location or a sublocation within a location.

**Label:** Type  
**Sortable:** No  
**Possible Values:**
- `FACILITY_LOCATION` - Location
- `FACILITY_SUBLOCATION` - Sublocation

## Relations

### location

- **Related Collection:** facility
- **Label:** Location

**Example Query:**

GraphQL

```graphql
query {
  facilityViewConnection(first: 10) {
    edges {
      node {
        location {
          name
          facilityUrl
        }
      }
    }
  }
}
```

## Filters

### controlTypeId

- **Label:** Control type
- **Type:** List|FacilityControlTypeString
- **Enabled:** Yes

**Filter Type:** Text value

### facilityUrl

- **Label:** Facility
- **Type:** List|FacilityUrlString
- **Enabled:** Yes

**Filter Type:** Text value

### parentFacilityUrl

- **Label:** Parent facility
- **Type:** List|FacilityUrlLocationString
- **Enabled:** Yes

**Filter Type:** Reference to facility collection

### search

- **Label:** Not specified
- **Type:** SearchString
- **Enabled:** Yes

**Filter Type:** Search text

### status

- **Label:** Status
- **Type:** List|FacilityStatusString
- **Enabled:** Yes

**Filter Type:** Text value

### type

- **Label:** Type
- **Type:** List|String
- **Enabled:** Yes
- **Options:**
  - Location (FACILITY_LOCATION)
  - Sublocation (FACILITY_SUBLOCATION)
