Add metaobject instances management API#17
Open
mtylty wants to merge 2 commits into
Open
Conversation
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 <noreply@anthropic.com>
- 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 <noreply@anthropic.com>
There was a problem hiding this comment.
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, anddelete_metaobjectmethods with GraphQL implementations and error handling. - Updates README checklist to mark metaobject instances management API and delete functionality as completed.
- Leverages
log_timefor 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? |
There was a problem hiding this comment.
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? |
| 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." |
There was a problem hiding this comment.
[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." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request implements comprehensive metaobject instances management functionality, extending the
ShopifyToolkit::MetaobjectStatementsmodule 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:
handle_shopify_admin_client_errorsmethodlog_timedecorator for performance monitoring on write operationsImplementation details:
metaobjectCreate,metaobjectUpdate, andmetaobjectDeletemutationsmetaobjectandmetaobjectsqueries for data retrievalDocumentation updates: