-
Notifications
You must be signed in to change notification settings - Fork 0
Add portable metaobject definitions and references to Shopify Toolkit schema dump #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gianlukk994
merged 10 commits into
main
from
gianlukk994/support-metaobjects-schema-dump
Oct 31, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bed1855
Add portable metaobject references in schema dumps
gianlukk994 6746c08
Add metaobject definitions to schema dump
gianlukk994 0f2c205
Separate metaobjects and metafields schema parse
gianlukk994 505237f
Extract common metaobject methods to shared module
gianlukk994 9cd61f9
Handle metaobject reference fields on creation
gianlukk994 46c1ddc
Enhance schema dump with multiple metaobject IDs
gianlukk994 979ebb0
Add metaobject statements to migrator
gianlukk994 ddab845
Handle failed metafield creation with context
gianlukk994 7d34277
Defer field validation for metaobjects
gianlukk994 25a2276
Update README
gianlukk994 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "active_support/concern" | ||
|
|
||
| module ShopifyToolkit::MetaobjectUtilities | ||
| extend ActiveSupport::Concern | ||
| include ShopifyToolkit::AdminClient | ||
|
|
||
| def is_metaobject_reference_type?(type) | ||
| type.to_sym.in?([:metaobject_reference, :"list.metaobject_reference", :mixed_reference, :"list.mixed_reference"]) | ||
| end | ||
|
|
||
| def convert_validations_types_to_gids(validations) | ||
| return validations unless validations&.any? | ||
|
|
||
| validations.filter_map do |validation| | ||
| convert_metaobject_validation(validation) | ||
| end | ||
| end | ||
|
|
||
| def get_metaobject_definition_gid(type) | ||
| result = | ||
| shopify_admin_client | ||
| .query( | ||
| query: | ||
| "# GraphQL | ||
| query GetMetaobjectDefinitionID($type: String!) { | ||
| metaobjectDefinitionByType(type: $type) { | ||
| id | ||
| } | ||
| }", | ||
gianlukk994 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| variables: { type: type.to_s }, | ||
| ) | ||
| .tap { handle_shopify_admin_client_errors(_1) } | ||
| .body | ||
|
|
||
| gid = result.dig("data", "metaobjectDefinitionByType", "id") | ||
|
|
||
| return gid | ||
| end | ||
|
|
||
| def get_metaobject_definition_type_by_gid(gid) | ||
| result = | ||
| shopify_admin_client | ||
| .query( | ||
| query: | ||
| "# GraphQL | ||
| query GetMetaobjectDefinitionType($id: ID!) { | ||
| metaobjectDefinition(id: $id) { | ||
| type | ||
| } | ||
| }", | ||
gianlukk994 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| variables: { id: gid }, | ||
| ) | ||
| .tap { handle_shopify_admin_client_errors(_1) } | ||
| .body | ||
|
|
||
| result.dig("data", "metaobjectDefinition", "type") | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def convert_metaobject_validation(validation) | ||
| name = validation[:name] || validation["name"] | ||
| value = validation[:value] || validation["value"] | ||
|
|
||
| return validation unless metaobject_type_validation?(name) && value | ||
|
|
||
| parsed_value = parse_json_if_needed(value) | ||
| convert_types_to_gids(parsed_value) | ||
| end | ||
|
|
||
| def metaobject_type_validation?(name) | ||
| name.in?(["metaobject_definition_type", "metaobject_definition_types"]) | ||
| end | ||
|
|
||
| def parse_json_if_needed(value) | ||
| return value unless value.is_a?(String) && value.start_with?("[") && value.end_with?("]") | ||
|
|
||
| JSON.parse(value) | ||
| rescue JSON::ParserError | ||
| value | ||
| end | ||
|
|
||
| def convert_types_to_gids(value) | ||
| if value.is_a?(Array) | ||
| convert_array_types_to_gids(value) | ||
| else | ||
| convert_single_type_to_gid(value) | ||
| end | ||
| end | ||
|
|
||
| def convert_array_types_to_gids(types) | ||
| gids = types.map do |type| | ||
| gid = get_metaobject_definition_gid(type) | ||
| raise "Metaobject type '#{type}' not found" unless gid | ||
| gid | ||
| end | ||
| { name: "metaobject_definition_ids", value: gids.to_json } | ||
| end | ||
|
|
||
| def convert_single_type_to_gid(type) | ||
| gid = get_metaobject_definition_gid(type) | ||
| raise "Metaobject type '#{type}' not found" unless gid | ||
| { name: "metaobject_definition_id", value: gid } | ||
| end | ||
| end | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.