Migration guide: InventoryItem data field
Audience Programmer
Since pyck v0.27.0
Overview
Section titled “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
Section titled “What changed”Before: InventoryItem had a separate inventoryJSONData field for storing custom JSON data.
type InventoryItem { id: ID! sku: String! inventoryJSONData: Map # Removed # ... other fields}After: InventoryItem uses the unified data field (type Map).
type InventoryItem implements NodeInventory { id: ID! sku: String! data: Map # ... other fields}Breaking changes
Section titled “Breaking changes”- Field Removed: The
inventoryJSONDatafield no longer exists onInventoryItem - Database Migration: The
inventory_json_datacolumn has been removed from the items table - Data Preserved: All data previously stored in
inventoryJSONDatahas been migrated to thedatafield
Migration steps
Section titled “Migration steps”Step 1: Update GraphQL queries
Section titled “Step 1: Update GraphQL queries”Replace all occurrences of inventoryJSONData with data in your queries.
Before:
query GetInventoryItems { inventoryItems(first: 10) { edges { node { id sku inventoryJSONData } } }}After:
query GetInventoryItems { inventoryItems(first: 10) { edges { node { id sku data } } }}Step 2: Update mutations
Section titled “Step 2: Update mutations”Update create and update mutations to use data instead of inventoryJSONData.
Before:
mutation CreateItem($input: CreateInventoryItemInput!) { createInventoryItem(input: $input) { id sku inventoryJSONData }}
# Variables{ "input": { "sku": "ITEM-001", "inventoryJSONData": { "weight": 1.5, "color": "blue" } }}After:
mutation CreateItem($input: CreateInventoryItemInput!) { createInventoryItem(input: $input) { inventoryItem { id sku data } }}
# Variables{ "input": { "sku": "ITEM-001", "data": { "weight": 1.5, "color": "blue" } }}Step 3: Update filter queries
Section titled “Step 3: Update filter queries”Update where clauses that filter on JSON data fields.
Before:
query GetItemsByWeight { inventoryItems( where: { inventoryJSONDataHasKey: "weight" } ) { edges { node { id sku inventoryJSONData } } }}After:
query GetItemsByWeight { inventoryItems( where: { DataHasKey: "weight" } ) { edges { node { id sku data } } }}Step 4: Update client code
Section titled “Step 4: Update client code”Update your client code to use the new field name.
Before (JavaScript):
const items = response.data.inventoryItems.edges.map(edge => ({ id: edge.node.id, sku: edge.node.sku, customData: edge.node.inventoryJSONData}));After (JavaScript):
const items = response.data.inventoryItems.edges.map(edge => ({ id: edge.node.id, sku: edge.node.sku, customData: edge.node.data}));Complete migration examples
Section titled “Complete migration examples”Example 1: Query with custom data
Section titled “Example 1: Query with custom data”Before:
query GetItemsWithMetadata { inventoryItems( first: 20, where: { inventoryJSONDataHasKey: "metadata" } ) { edges { node { id sku inventoryJSONData createdAt } } totalCount }}After:
query GetItemsWithMetadata { inventoryItems( first: 20, where: { DataHasKey: "metadata" } ) { edges { node { id sku data createdAt } } totalCount }}Example 2: Create item with custom data
Section titled “Example 2: Create item with custom data”Before:
mutation CreateProductItem { createInventoryItem(input: { sku: "PROD-12345", inventoryJSONData: { category: "electronics", manufacturer: "Acme Corp", warranty: "2 years" } }) { id sku inventoryJSONData }}After:
mutation CreateProductItem { createInventoryItem(input: { sku: "PROD-12345", data: { category: "electronics", manufacturer: "Acme Corp", warranty: "2 years" } }) { inventoryItem { id sku data } }}Example 3: Update item custom data
Section titled “Example 3: Update item custom data”Before:
mutation UpdateItemData($id: ID!, $newData: Map!) { updateInventoryItem(id: $id, input: { inventoryJSONData: $newData }) { id sku inventoryJSONData }}After:
mutation UpdateItemData($id: ID!, $newData: Map!) { updateInventoryItem(id: $id, input: { data: $newData }) { inventoryItem { id sku data } }}Effect on entity types
Section titled “Effect on entity types”Entity types now use the same data field of type Map. Shared mixins across entity types reduce duplication in the schema, and the filter names (DataHasKey, DataContains, etc.) are the same across all entity types.
Filter input changes
Section titled “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
Section titled “Troubleshooting”Error: Cannot query field inventoryJSONData on type InventoryItem
Section titled “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:
# WronginventoryItems { edges { node { inventoryJSONData } }}
# CorrectinventoryItems { edges { node { data } }}Error: Field inventoryJSONDataHasKey is not defined
Section titled “Error: Field inventoryJSONDataHasKey is not defined”Update your where clause to use the new filter field names:
# Wrongwhere: { inventoryJSONDataHasKey: "category"}
# Correctwhere: { DataHasKey: "category"}