Remove Products From Collection
Remove Products from Collection Mutation
Note: This mutation may not be directly available in the current GraphQL schema. This is a conceptual example of what a product removal mutation might look like based on common e-commerce patterns.
Use Cases​
- Collection Cleanup: Remove outdated or discontinued products
- Seasonal Updates: Remove off-season products from collections
- Product Reorganization: Move products between collections
- Inventory Management: Remove out-of-stock products from featured collections
- Marketing Campaigns: Remove products from promotional collections
- Bulk Operations: Efficiently remove multiple products at once
Key Features​
Bulk Product Removal​
- Multiple Products: Remove several products from a collection in one operation
- Efficient Processing: Single API call for multiple relationship removals
- Atomic Operation: All products are removed together or none at all
- Safe Operation: Products remain in the store, only collection relationship is removed
Collection Management​
- Existing Collections: Remove products from any existing collection
- Product Validation: Ensures all products exist before attempting removal
- Relationship Management: Cleanly removes product-collection links
- Status Preservation: Maintains existing collection and product statuses
Response Data​
- Updated Collection: Returns the collection with updated product list
- Removal Confirmation: Lists which products were successfully removed
- Remaining Products: Shows products still in the collection
- Error Handling: Reports any products that couldn't be removed
Input Parameters​
$storeId: ID!- The unique identifier of the store$id: ID!- The unique identifier of the collection to remove products from$productIds: [ID!]!- Array of product IDs to remove from the collection
Response Structure​
The mutation would return a CollectionRemoveProductsPayload containing:
collection: Updated collection object with products removedremovedProductIds: Array of product IDs that were successfully removed- Collection metadata and remaining products
- Confirmation of successful removals
Collection Fields Detail​
Basic Information​
id- Unique collection identifiertitle- Collection namehandle- URL-friendly collection slugdescriptionHtml- Full HTML collection descriptionshortDescription- Brief collection summaryisVisible/isArchived- Collection status flagslocale- Primary languagecreatedAt/updatedAt- Timestamps (updatedAt reflects the removal)
Remaining Products​
products- Paginated list of products still in the collectiontotalCount- Updated count of remaining products- Product details including images, pricing, and availability
- Pagination information for remaining products
Removal Confirmation​
removedProductIds- Array of successfully removed product IDs- Error information for any products that couldn't be removed
- Status of the removal operation
Example Response​
{
"data": {
"removeProductsFromCollection": {
"collection": {
"id": "Collection_electronics_001",
"title": "Electronics & Gadgets",
"handle": "electronics-gadgets",
"descriptionHtml": "<p>Discover our curated collection...</p>",
"shortDescription": "Cutting-edge electronics and innovative gadgets",
"isVisible": true,
"isArchived": false,
"locale": "en",
"updatedAt": "2024-01-15T15:45:00Z",
"products": {
"totalCount": 5,
"nodes": [
{
"id": "Product_smartphone_galaxy_001",
"title": "Samsung Galaxy S24 Ultra",
"handle": "samsung-galaxy-s24-ultra",
"status": "ACTIVE",
"isVisible": true,
"variants": {
"nodes": [
{
"id": "Variant_galaxy_256gb_001",
"price": {
"amount": 1199.99,
"currencyCode": "USD"
},
"quantity": 25,
"isAvailable": true
}
]
},
"collections": {
"totalCount": 1
}
}
],
"pageInfo": {
"hasNextPage": false,
"hasPreviousPage": false,
"startCursor": "cursor_start",
"endCursor": "cursor_end"
}
}
},
"removedProductIds": [
"Product_old_smartphone_001",
"Product_discontinued_laptop_002",
"Product_outdated_tablet_003"
]
}
}
}
Implementation Notes​
Validation Requirements​
- Store ID must be valid and accessible
- Collection ID must exist within the specified store
- Product IDs should exist (non-existent IDs are typically ignored)
- User must have permissions to modify the collection
- Products must currently be in the collection to be removed
Best Practices​
- Verify products are actually in the collection before removal
- Consider the impact on collection completeness and theme
- Update collection metadata if removing significant products
- Monitor collection size to ensure it remains meaningful
- Document reasons for product removals for audit purposes
Error Handling​
- Handle invalid store or collection IDs gracefully
- Skip invalid or non-existent product IDs
- Handle permission errors for restricted collections
- Ignore products not currently in the collection
- Provide clear feedback on successful and failed removals
Performance Considerations​
- Limit the number of products removed in a single operation
- Consider collection cache invalidation after removals
- Update search indexes when products are removed
- Monitor database performance with large removal operations
- Batch removals for better efficiency
Removal Behavior​
Product Status​
- Products Remain: Products are not deleted, only removed from the collection
- Other Collections: Products may still belong to other collections
- Store Catalog: Products remain available in the main store catalog
- Search Results: Products may still appear in search results
Collection Updates​
- Product Count: Total product count is updated
- Updated Timestamp: Collection's updatedAt timestamp is modified
- Cache Invalidation: Collection caches are refreshed
- Search Indexes: Collection-based search indexes are updated
Alternative Implementation​
Since this mutation may not be directly available, product removal might happen through:
- Product Update: Remove collections through product update mutations
- Collection Update: Update collection with new product list
- Batch Operations: Bulk collection management operations
- Admin Interface: Collection management through admin panels
Related Operations​
addProductsToCollection- Add products to collectionsupdateCollection- Update collection information and productsupdateProduct- Update product collection relationshipscreateCollection- Create collections with initial productsListStoreProducts- Query products in collections
Use Case Examples​
Seasonal Collection Cleanup​
{
"storeId": "Store_example_001",
"id": "Collection_winter_2023",
"productIds": [
"Product_winter_coat_001",
"Product_snow_boots_002",
"Product_winter_gloves_003"
]
}
Discontinued Product Removal​
{
"storeId": "Store_example_001",
"id": "Collection_featured_products",
"productIds": [
"Product_discontinued_phone_001",
"Product_old_model_laptop_002"
]
}
Collection Reorganization​
{
"storeId": "Store_example_001",
"id": "Collection_premium_electronics",
"productIds": [
"Product_budget_phone_001",
"Product_entry_level_tablet_002"
]
}
Error Scenarios​
Common Errors​
- Collection Not Found: Invalid collection ID
- Permission Denied: Insufficient permissions to modify collection
- Product Not in Collection: Attempting to remove products not in the collection
- Store Mismatch: Products don't belong to the specified store
Error Response Example​
{
"errors": [
{
"message": "Product Product_nonexistent_001 not found in collection",
"extensions": {
"code": "PRODUCT_NOT_IN_COLLECTION",
"productId": "Product_nonexistent_001"
}
}
],
"data": {
"removeProductsFromCollection": {
"collection": { /* updated collection */ },
"removedProductIds": [
"Product_old_smartphone_001",
"Product_discontinued_laptop_002"
]
}
}
}
GraphQL Endpoint​
https://graphql.wuilt.com
Operation: may​
Try It Out​
Query​
Query Variables
1
2
3
4
5
6
7
8
9
Note: Make sure to change the storeId with your store ID. For guidance on how to get your store ID, reference the Store ID guide.
Authentication​
To use this query, you will need an API key. Click the "API Key" button in the navigation bar to enter your credentials.