> For the complete documentation index, see [llms.txt](https://docs.pyck.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pyck.cloud/development/migrations/inventory-item-data-field.md).

# InventoryItem Data Field

Migration guide for the breaking change from inventoryJSONData to the unified data field

Audience: Programmer

## Overview

This guide covers a breaking change in the pyck GraphQL API where the `inventoryJSONData` field has been removed from the `InventoryItem` type. This field has been replaced with the unified `data` field that is now available across all entity types through the shared DataMixin.

## What Changed

**Before**: InventoryItem had a separate `inventoryJSONData` field for storing custom JSON data.

```graphql
type InventoryItem {
  id: ID!
  sku: String!
  inventoryJSONData: Map  # Removed
  # ... other fields
}
```

**After**: InventoryItem uses the unified `data` field from the WithCustomData interface.

```graphql
type InventoryItem implements WithCustomData {
  id: ID!
  sku: String!
  data: Map
  # ... other fields
}
```

## Breaking Changes

1. **Field Removed**: The `inventoryJSONData` field no longer exists on `InventoryItem`
2. **Database Migration**: The `inventory_json_data` column has been removed from the items table
3. **Data Preserved**: All data previously stored in `inventoryJSONData` has been migrated to the `data` field

## Migration Steps

### Step 1: Update GraphQL Queries

Replace all occurrences of `inventoryJSONData` with `data` in your queries.

**Before:**

```graphql
query GetInventoryItems {
  inventoryItems(first: 10) {
    edges {
      node {
        id
        sku
        inventoryJSONData
      }
    }
  }
}
```

**After:**

```graphql
query GetInventoryItems {
  inventoryItems(first: 10) {
    edges {
      node {
        id
        sku
        data
      }
    }
  }
}
```

### Step 2: Update Mutations

Update create and update mutations to use `data` instead of `inventoryJSONData`.

**Before:**

```graphql
mutation CreateItem($input: CreateInventoryItemInput!) {
  createInventoryItem(input: $input) {
    id
    sku
    inventoryJSONData
  }
}

# Variables
{
  "input": {
    "sku": "ITEM-001",
    "inventoryJSONData": {
      "weight": 1.5,
      "color": "blue"
    }
  }
}
```

**After:**

```graphql
mutation CreateItem($input: CreateInventoryItemInput!) {
  createInventoryItem(input: $input) {
    id
    sku
    data
  }
}

# Variables
{
  "input": {
    "sku": "ITEM-001",
    "data": {
      "weight": 1.5,
      "color": "blue"
    }
  }
}
```

### Step 3: Update Filter Queries

Update where clauses that filter on JSON data fields.

**Before:**

```graphql
query GetItemsByWeight {
  inventoryItems(
    where: {
      inventoryJSONDataHasKey: "weight"
    }
  ) {
    edges {
      node {
        id
        sku
        inventoryJSONData
      }
    }
  }
}
```

**After:**

```graphql
query GetItemsByWeight {
  inventoryItems(
    where: {
      dataHasKey: "weight"
    }
  ) {
    edges {
      node {
        id
        sku
        data
      }
    }
  }
}
```

### Step 4: Update Client Code

Update your client code to use the new field name.

**Before (JavaScript):**

```javascript
const items = response.data.inventoryItems.edges.map(edge => ({
  id: edge.node.id,
  sku: edge.node.sku,
  customData: edge.node.inventoryJSONData
}));
```

**After (JavaScript):**

```javascript
const items = response.data.inventoryItems.edges.map(edge => ({
  id: edge.node.id,
  sku: edge.node.sku,
  customData: edge.node.data
}));
```

## Complete Migration Examples

### Example 1: Query with Custom Data

**Before:**

```graphql
query GetItemsWithMetadata {
  inventoryItems(
    first: 20,
    where: {
      inventoryJSONDataHasKey: "metadata"
    }
  ) {
    edges {
      node {
        id
        sku
        inventoryJSONData
        createdAt
      }
    }
    totalCount
  }
}
```

**After:**

```graphql
query GetItemsWithMetadata {
  inventoryItems(
    first: 20,
    where: {
      dataHasKey: "metadata"
    }
  ) {
    edges {
      node {
        id
        sku
        data
        createdAt
      }
    }
    totalCount
  }
}
```

### Example 2: Create Item with Custom Data

**Before:**

```graphql
mutation CreateProductItem {
  createInventoryItem(input: {
    sku: "PROD-12345",
    inventoryJSONData: {
      category: "electronics",
      manufacturer: "Acme Corp",
      warranty: "2 years"
    }
  }) {
    id
    sku
    inventoryJSONData
  }
}
```

**After:**

```graphql
mutation CreateProductItem {
  createInventoryItem(input: {
    sku: "PROD-12345",
    data: {
      category: "electronics",
      manufacturer: "Acme Corp",
      warranty: "2 years"
    }
  }) {
    id
    sku
    data
  }
}
```

### Example 3: Update Item Custom Data

**Before:**

```graphql
mutation UpdateItemData($id: ID!, $newData: Map!) {
  updateInventoryItem(id: $id, input: {
    inventoryJSONData: $newData
  }) {
    id
    sku
    inventoryJSONData
  }
}
```

**After:**

```graphql
mutation UpdateItemData($id: ID!, $newData: Map!) {
  updateInventoryItem(id: $id, input: {
    data: $newData
  }) {
    id
    sku
    data
  }
}
```

## Benefits of This Change

1. **Consistency**: All entity types now use the same `data` field through the `WithCustomData` interface
2. **Simplified Schema**: Reduces duplication by using shared mixins across entity types
3. **Unified Filtering**: Consistent filter names (`dataHasKey`, `dataContains`, etc.) across all entity types
4. **Better Type System**: Leverages GraphQL interfaces for shared behavior

## Filter Input Changes

The following filter fields have been renamed for consistency:

| Old Field Name              | New Field Name |
| --------------------------- | -------------- |
| `inventoryJSONData`         | `data`         |
| `inventoryJSONDataHasKey`   | `dataHasKey`   |
| `inventoryJSONDataIn`       | `dataIn`       |
| `inventoryJSONDataContains` | `dataContains` |

## Troubleshooting

### Error: Cannot query field "inventoryJSONData" on type "InventoryItem"

This error indicates you are still using the old field name. Update your query to use `data`:

```graphql
# Wrong
inventoryItems {
  edges {
    node {
      inventoryJSONData
    }
  }
}

# Correct
inventoryItems {
  edges {
    node {
      data
    }
  }
}
```

### Error: Field "inventoryJSONDataHasKey" is not defined

Update your where clause to use the new filter field names:

```graphql
# Wrong
where: {
  inventoryJSONDataHasKey: "category"
}

# Correct
where: {
  dataHasKey: "category"
}
```

## Related Documentation

* [WithCustomData Interface](https://github.com/pyck-ai/docs/blob/main/development/graphql/interfaces/WithCustomData.md)
* [InventoryItem Type](https://github.com/pyck-ai/docs/blob/main/development/graphql/types/InventoryItem.md)
* [Advanced JSON Field Queries](https://github.com/pyck-ai/docs/blob/main/development/graphql/advanced/json-field-queries.md)
* [Map Scalar](https://github.com/pyck-ai/docs/blob/main/development/graphql/scalars/Map.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.pyck.cloud/development/migrations/inventory-item-data-field.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
