shopify_toolkit 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/shopify_toolkit/schema.rb +90 -44
- data/lib/shopify_toolkit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e5e83e71a4d7f6e6d0d8746e307076e7908f4e6c03d28820e99fde10557c6ba
|
4
|
+
data.tar.gz: c9d9bce64d5af477e1e46a18dc18b175088fde22288c2d97e935c495f06beb42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c39acdbf5c2b15e1b0c5276aefd65063857bae0da5431b9a929b55d2d8fe51517ba40c71ffe508ddda2100965c378f9a99c494de398afc906cfdb5674e65b7c
|
7
|
+
data.tar.gz: cfa96c9301a1502eb02ba5fb5c854ffa8a5e72a4960910ba17cd82d475c9edeeab39989fe5d5f6c879b94b7f55835be6e334100cec24304ba1a56621e0fb5faa
|
@@ -8,7 +8,37 @@ module ShopifyToolkit::Schema
|
|
8
8
|
extend self
|
9
9
|
include ShopifyToolkit::MetafieldStatements
|
10
10
|
include ShopifyToolkit::Migration::Logging
|
11
|
+
|
12
|
+
delegate :logger, to: Rails
|
13
|
+
|
11
14
|
SCHEMA_PATH = "config/shopify/schema.rb"
|
15
|
+
# https://shopify.dev/docs/api/admin-graphql/2024-10/enums/MetafieldOwnerType
|
16
|
+
OWNER_TYPES = %i[
|
17
|
+
api_permissions
|
18
|
+
articles
|
19
|
+
blogs
|
20
|
+
carttransforms
|
21
|
+
collections
|
22
|
+
companies
|
23
|
+
company_locations
|
24
|
+
customers
|
25
|
+
delivery_customizations
|
26
|
+
discounts
|
27
|
+
draftorders
|
28
|
+
fulfillment_constraint_rules
|
29
|
+
gift_card_transactions
|
30
|
+
locations
|
31
|
+
markets
|
32
|
+
orders
|
33
|
+
order_routing_location_rules
|
34
|
+
pages
|
35
|
+
payment_customizations
|
36
|
+
products
|
37
|
+
productvariants
|
38
|
+
selling_plans
|
39
|
+
shops
|
40
|
+
validations
|
41
|
+
].freeze
|
12
42
|
|
13
43
|
def load!
|
14
44
|
path = Rails.root.join(SCHEMA_PATH)
|
@@ -38,10 +68,12 @@ module ShopifyToolkit::Schema
|
|
38
68
|
instance_eval(&block)
|
39
69
|
end
|
40
70
|
|
41
|
-
def fetch_definitions
|
71
|
+
def fetch_definitions(owner_type:)
|
72
|
+
owner_type = owner_type.to_s.singularize.upcase
|
73
|
+
|
42
74
|
query = <<~GRAPHQL
|
43
75
|
query {
|
44
|
-
metafieldDefinitions(first: 250, ownerType:
|
76
|
+
metafieldDefinitions(first: 250, ownerType: #{owner_type}) {
|
45
77
|
nodes {
|
46
78
|
id
|
47
79
|
name
|
@@ -74,57 +106,71 @@ module ShopifyToolkit::Schema
|
|
74
106
|
}
|
75
107
|
GRAPHQL
|
76
108
|
|
77
|
-
result =
|
109
|
+
result =
|
110
|
+
shopify_admin_client
|
111
|
+
.query(query:)
|
112
|
+
.tap { handle_shopify_admin_client_errors(_1) }
|
113
|
+
.body
|
78
114
|
|
79
115
|
result.dig("data", "metafieldDefinitions", "nodes") || []
|
80
116
|
end
|
81
117
|
|
82
118
|
def generate_schema_content
|
83
|
-
definitions =
|
119
|
+
definitions =
|
120
|
+
OWNER_TYPES.flat_map { |owner_type| fetch_definitions(owner_type:) }
|
121
|
+
|
84
122
|
content = StringIO.new
|
85
123
|
content << <<~RUBY
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
124
|
+
# This file is auto-generated from the current state of the Shopify metafields.
|
125
|
+
# Instead of editing this file, please use the metafields migration feature of ShopifyToolkit
|
126
|
+
# to incrementally modify your metafields, and then regenerate this schema definition.
|
127
|
+
#
|
128
|
+
# This file is the source used to define your metafields when running `bin/rails shopify:schema:load`.
|
129
|
+
#
|
130
|
+
# It's strongly recommended that you check this file into your version control system.
|
131
|
+
ShopifyToolkit::Schema.define do
|
132
|
+
RUBY
|
133
|
+
|
134
|
+
# Sort for consistent output
|
135
|
+
definitions
|
136
|
+
.sort_by { [_1["ownerType"], _1["namespace"], _1["key"]] }
|
137
|
+
.each do
|
138
|
+
owner_type = _1["ownerType"].downcase.pluralize.to_sym
|
139
|
+
key = _1["key"].to_sym
|
140
|
+
type = _1["type"]["name"].to_sym
|
141
|
+
name = _1["name"]
|
142
|
+
namespace = _1["namespace"]&.to_sym
|
143
|
+
description = _1["description"]
|
144
|
+
validations = _1["validations"]&.map { |v| v.transform_keys(&:to_sym) }
|
145
|
+
capabilities =
|
146
|
+
_1["capabilities"]
|
147
|
+
&.transform_keys(&:to_sym)
|
148
|
+
&.transform_values { |v| v.transform_keys(&:to_sym) }
|
149
|
+
|
150
|
+
args = [owner_type, key, type]
|
151
|
+
kwargs = { name: name }
|
152
|
+
kwargs[:namespace] = namespace if namespace && namespace != :custom
|
153
|
+
kwargs[:description] = description if description
|
154
|
+
kwargs[:validations] = validations if validations.present?
|
155
|
+
|
156
|
+
# Only include capabilities if they have non-default values
|
157
|
+
if capabilities.present?
|
158
|
+
has_non_default_capabilities =
|
159
|
+
capabilities.any? do |cap, value|
|
160
|
+
case cap
|
161
|
+
when :smartCollectionCondition, :adminFilterable
|
162
|
+
value[:enabled] == true
|
163
|
+
else
|
164
|
+
true
|
165
|
+
end
|
121
166
|
end
|
122
|
-
|
123
|
-
|
124
|
-
end
|
167
|
+
kwargs[:capabilities] = capabilities if has_non_default_capabilities
|
168
|
+
end
|
125
169
|
|
126
|
-
|
127
|
-
|
170
|
+
args_string = args.map(&:inspect).join(", ")
|
171
|
+
kwargs_string = kwargs.map { |k, v| "#{k}: #{v.inspect}" }.join(", ")
|
172
|
+
content.puts " create_metafield #{args_string}, #{kwargs_string}"
|
173
|
+
end
|
128
174
|
|
129
175
|
content.puts "end"
|
130
176
|
content.string
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopify_toolkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elia Schito
|
8
8
|
- Nebulab Team
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-04-
|
11
|
+
date: 2025-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|