Module: ShopifyToolkit::MetafieldStatements
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/shopify_toolkit/metafield_statements.rb
Constant Summary
Constants included from AdminClient
Class Method Summary collapse
Instance Method Summary collapse
Methods included from MetaobjectUtilities
#convert_validations_types_to_gids, #get_metaobject_definition_gid, #get_metaobject_definition_type_by_gid, #is_metaobject_reference_type?
Methods included from AdminClient
#api_version, #handle_shopify_admin_client_errors, #shopify_admin_client
Methods included from ShopifyToolkit::Migration::Logging
#announce, #say, #say_with_time, #write
Class Method Details
.define(&block) ⇒ Object
171 172 173 174 175 176 177 |
# File 'lib/shopify_toolkit/metafield_statements.rb', line 171 def self.define(&block) context = Object.new context.extend(self) context.instance_eval(&block) if block_given?(&block) context end |
.log_time(method_name) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/shopify_toolkit/metafield_statements.rb', line 11 def self.log_time(method_name) current_method = instance_method(method_name) define_method(method_name) do |*args, **kwargs, &block| say_with_time("#{method_name}(#{args.map(&:inspect).join(', ')})") { current_method.bind(self).call(*args, **kwargs, &block) } end end |
Instance Method Details
#get_metafield_gid(owner_type, key, namespace: :custom) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/shopify_toolkit/metafield_statements.rb', line 69 def (owner_type, key, namespace: :custom) ownerType = owner_type.to_s.singularize.upcase # Eg. "PRODUCT" result = shopify_admin_client .query( query: "# GraphQL query FindMetafieldDefinition($ownerType: MetafieldOwnerType!, $key: String!) { metafieldDefinitions(first: 1, ownerType: $ownerType, key: $key) { nodes { id } } }", variables: { ownerType:, key:, namespace:, }, ) .tap { handle_shopify_admin_client_errors(_1) } .body result.dig("data", "metafieldDefinitions", "nodes", 0, "id") end |