Skip to content

Conversation

mtylty
Copy link
Member

@mtylty mtylty commented Jun 17, 2025

This pull request implements comprehensive metaobject instances management functionality, extending the ShopifyToolkit::MetaobjectStatements module with full CRUD operations for metaobject instances.

New functionality for managing Shopify metaobject instances:

  • Method create_metaobject: Creates new metaobject instances with validation to ensure the metaobject definition exists. Includes built-in checks to skip creation if an instance with the same handle already exists. (lib/shopify_toolkit/metaobject_statements.rb)

  • Method find_metaobject: Retrieves a single metaobject instance by type and handle, returning the complete metaobject data including all fields. (lib/shopify_toolkit/metaobject_statements.rb)

  • Method find_metaobjects: Queries multiple metaobjects by type with support for filtering, sorting, and pagination. Supports all Shopify GraphQL query parameters including first, query filters, sortKey, and reverse ordering. (lib/shopify_toolkit/metaobject_statements.rb)

  • Method update_metaobject: Updates existing metaobject instances by handle or GID. Gracefully handles cases where the metaobject doesn't exist with user-friendly feedback. (lib/shopify_toolkit/metaobject_statements.rb)

  • Method delete_metaobject: Deletes metaobject instances by handle or GID with proper error handling and user feedback for non-existent objects. (lib/shopify_toolkit/metaobject_statements.rb)

Key features:

  • Complete CRUD operations for metaobject instances using Shopify's GraphQL Admin API
  • Supports both handle and GID-based operations for maximum flexibility
  • Proper error handling through the existing handle_shopify_admin_client_errors method
  • Gracefully handles edge cases with informative user feedback
  • Follows established code patterns and conventions in the module
  • Includes the log_time decorator for performance monitoring on write operations
  • Full GraphQL query and mutation implementations following Shopify's latest API documentation

Implementation details:

  • Uses metaobjectCreate, metaobjectUpdate, and metaobjectDelete mutations
  • Leverages metaobject and metaobjects queries for data retrieval
  • Maintains consistency with existing metafield and metaobject definition management patterns
  • Provides comprehensive field mapping and data transformation
  • Updates project README to reflect completed roadmap milestone

Documentation updates:

  • README.md: Updated the roadmap to mark "Metaobject Instances management API" as completed, and also marked "Delete" functionality for Metaobject Definitions as completed from the previous PR.

mtylty and others added 2 commits June 17, 2025 17:03
Implements the delete_metaobject_definition method to complete the CRUD operations for metaobject definitions management API. The method follows the same patterns as create and update methods, including proper error handling and logging.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Implements create_metaobject for creating metaobject instances
- Adds find_metaobject to retrieve single metaobjects by handle
- Adds find_metaobjects to query multiple metaobjects with filtering
- Implements update_metaobject for modifying existing instances
- Implements delete_metaobject for removing metaobject instances
- Supports both handle and GID-based operations
- Includes proper error handling and user feedback
- Follows existing code patterns and conventions
- Updates README roadmap to mark completion

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@mtylty mtylty requested review from Copilot and elia June 17, 2025 15:34
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces full CRUD support for Shopify metaobject instances and updates documentation to reflect completed functionality.

  • Adds create_metaobject, find_metaobject(s), update_metaobject, and delete_metaobject methods with GraphQL implementations and error handling.
  • Updates README checklist to mark metaobject instances management API and delete functionality as completed.
  • Leverages log_time for write operations and integrates with existing error handling patterns.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
lib/shopify_toolkit/metaobject_statements.rb Implements CRUD methods for managing metaobject instances via GraphQL
README.md Fixes roadmap items to mark delete and instances API as completed
Comments suppressed due to low confidence (1)

README.md:20

  • The markdown list items for Delete and Metaobject Instances management API are misaligned; please fix indentation and bullet syntax to ensure these checklist entries render correctly.
  - [x] Delete


metaobject_input = { type: type.to_s, **options }
metaobject_input[:handle] = handle if handle
metaobject_input[:fields] = fields.map { |field| { key: field[:key].to_s, value: field[:value].to_s } } if fields.any?
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting all field values to strings may lead to invalid types for non-string fields; consider preserving original value types or converting based on the metaobject field definitions.

Suggested change
metaobject_input[:fields] = fields.map { |field| { key: field[:key].to_s, value: field[:value].to_s } } if fields.any?
metaobject_input[:fields] = fields.map { |field| { key: field[:key].to_s, value: field[:value] } } if fields.any?

Copilot uses AI. Check for mistakes.

def create_metaobject(type, handle: nil, fields: [], **options)
# Check if metaobject definition exists
unless get_metaobject_definition_gid(type)
raise "Metaobject definition #{type} does not exist. Create it first."
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Raising a generic RuntimeError makes it harder to handle this specific error downstream; consider defining and using a more descriptive or custom exception class.

Suggested change
raise "Metaobject definition #{type} does not exist. Create it first."
raise MetaobjectDefinitionError, "Metaobject definition #{type} does not exist. Create it first."

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant