active_shopify_graphql 0.1.0 → 0.2.0
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2f8f9c57e3dd7f5371ace9fb8d3db79d796a0aa34890065d4727ae7a45a0723b
|
|
4
|
+
data.tar.gz: 16d8e5361a00e4aaa2b166ba8108496a8564e669fc16c76e68e4ed058df12a23
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c30453eafcf98bc563f309e2a5762373615ad9a23c0b8d0c6e3c0919e5e8490088974d0d187582e6a55b0d012d4cc2e9c3abcc77cb2c638bd4acd8098be1b032
|
|
7
|
+
data.tar.gz: 1b190403f8fcdee4d69d35b534c168b63200a87aca06a6cbf465ea09dc873b3d723597e3f99201acbd8e0d4ed9618897af028dbcf73653be891391cc6d383d23
|
|
@@ -80,9 +80,56 @@ module ActiveShopifyGraphQL
|
|
|
80
80
|
|
|
81
81
|
# Simple proxy class to handle loader delegation
|
|
82
82
|
class LoaderProxy
|
|
83
|
-
def initialize(model_class, loader)
|
|
83
|
+
def initialize(model_class, loader, included_connections: [], selected_attributes: nil)
|
|
84
84
|
@model_class = model_class
|
|
85
85
|
@loader = loader
|
|
86
|
+
@included_connections = included_connections
|
|
87
|
+
@selected_attributes = selected_attributes
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def includes(*connection_names)
|
|
91
|
+
# Validate connections exist
|
|
92
|
+
@model_class.send(:validate_includes_connections!, connection_names) if @model_class.respond_to?(:validate_includes_connections!, true)
|
|
93
|
+
|
|
94
|
+
# Collect connections with eager_load: true
|
|
95
|
+
auto_included_connections = @model_class.connections.select { |_name, config| config[:eager_load] }.keys
|
|
96
|
+
|
|
97
|
+
# Merge manual and automatic connections
|
|
98
|
+
all_included_connections = (@included_connections + connection_names + auto_included_connections).uniq
|
|
99
|
+
|
|
100
|
+
# Create a new loader with the included connections
|
|
101
|
+
new_loader = @loader.class.new(
|
|
102
|
+
@model_class,
|
|
103
|
+
*loader_extra_args,
|
|
104
|
+
selected_attributes: @selected_attributes,
|
|
105
|
+
included_connections: all_included_connections
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
LoaderProxy.new(
|
|
109
|
+
@model_class,
|
|
110
|
+
new_loader,
|
|
111
|
+
included_connections: all_included_connections,
|
|
112
|
+
selected_attributes: @selected_attributes
|
|
113
|
+
)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def select(*attribute_names)
|
|
117
|
+
new_selected = attribute_names.map(&:to_sym)
|
|
118
|
+
|
|
119
|
+
# Create a new loader with the selected attributes
|
|
120
|
+
new_loader = @loader.class.new(
|
|
121
|
+
@model_class,
|
|
122
|
+
*loader_extra_args,
|
|
123
|
+
selected_attributes: new_selected,
|
|
124
|
+
included_connections: @included_connections
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
LoaderProxy.new(
|
|
128
|
+
@model_class,
|
|
129
|
+
new_loader,
|
|
130
|
+
included_connections: @included_connections,
|
|
131
|
+
selected_attributes: new_selected
|
|
132
|
+
)
|
|
86
133
|
end
|
|
87
134
|
|
|
88
135
|
def find(id = nil)
|
|
@@ -116,6 +163,18 @@ module ActiveShopifyGraphQL
|
|
|
116
163
|
"#{@model_class.name}(with_#{@loader.class.name.demodulize})"
|
|
117
164
|
end
|
|
118
165
|
alias to_s inspect
|
|
166
|
+
|
|
167
|
+
private
|
|
168
|
+
|
|
169
|
+
# Returns extra arguments needed when creating a new loader of the same type
|
|
170
|
+
# For CustomerAccountApiLoader, this includes the token
|
|
171
|
+
def loader_extra_args
|
|
172
|
+
if @loader.is_a?(ActiveShopifyGraphQL::Loaders::CustomerAccountApiLoader)
|
|
173
|
+
[@loader.instance_variable_get(:@token)]
|
|
174
|
+
else
|
|
175
|
+
[]
|
|
176
|
+
end
|
|
177
|
+
end
|
|
119
178
|
end
|
|
120
179
|
end
|
|
121
180
|
end
|
|
@@ -12,7 +12,7 @@ module ActiveShopifyGraphQL
|
|
|
12
12
|
def graphql_query(model_type = nil)
|
|
13
13
|
type = model_type || graphql_type
|
|
14
14
|
if type == 'Customer'
|
|
15
|
-
|
|
15
|
+
QueryTree.build_current_customer_query(context)
|
|
16
16
|
else
|
|
17
17
|
super(type)
|
|
18
18
|
end
|
|
@@ -54,18 +54,6 @@ module ActiveShopifyGraphQL
|
|
|
54
54
|
logger.info("ActiveShopifyGraphQL Query (Customer Account API):\n#{query}")
|
|
55
55
|
logger.info("ActiveShopifyGraphQL Variables:\n#{variables}")
|
|
56
56
|
end
|
|
57
|
-
|
|
58
|
-
def customer_only_query(model_type = nil)
|
|
59
|
-
type = model_type || graphql_type
|
|
60
|
-
compact = ActiveShopifyGraphQL.configuration.compact_queries
|
|
61
|
-
frag = fragment
|
|
62
|
-
|
|
63
|
-
if compact
|
|
64
|
-
"#{frag} query getCurrentCustomer { #{query_name(type)} { ...#{fragment_name(type)} } }"
|
|
65
|
-
else
|
|
66
|
-
"#{frag}\n\nquery getCurrentCustomer {\n #{query_name(type)} {\n ...#{fragment_name(type)}\n }\n}\n"
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
57
|
end
|
|
70
58
|
end
|
|
71
59
|
end
|
|
@@ -27,6 +27,19 @@ module ActiveShopifyGraphQL
|
|
|
27
27
|
end.to_s
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
# Build a query that doesn't require an ID parameter (e.g., Customer Account API's current customer)
|
|
31
|
+
def self.build_current_customer_query(context, query_name: nil)
|
|
32
|
+
new(context).tap do |tree|
|
|
33
|
+
tree.add_fragment(FragmentBuilder.new(context).build)
|
|
34
|
+
tree.set_query_config(
|
|
35
|
+
type: :current_customer,
|
|
36
|
+
model_type: context.graphql_type,
|
|
37
|
+
query_name: query_name || context.query_name,
|
|
38
|
+
fragment_name: context.fragment_name
|
|
39
|
+
)
|
|
40
|
+
end.to_s
|
|
41
|
+
end
|
|
42
|
+
|
|
30
43
|
def self.build_collection_query(context, query_name:, variables:, connection_type: :nodes_only)
|
|
31
44
|
new(context).tap do |tree|
|
|
32
45
|
tree.add_fragment(FragmentBuilder.new(context).build)
|
|
@@ -80,6 +93,7 @@ module ActiveShopifyGraphQL
|
|
|
80
93
|
def to_s
|
|
81
94
|
case @query_config[:type]
|
|
82
95
|
when :single_record then render_single_record_query
|
|
96
|
+
when :current_customer then render_current_customer_query
|
|
83
97
|
when :collection then render_collection_query
|
|
84
98
|
when :connection then render_connection_query
|
|
85
99
|
else ""
|
|
@@ -113,6 +127,18 @@ module ActiveShopifyGraphQL
|
|
|
113
127
|
end
|
|
114
128
|
end
|
|
115
129
|
|
|
130
|
+
def render_current_customer_query
|
|
131
|
+
type = @query_config[:model_type]
|
|
132
|
+
query_name = @query_config[:query_name]
|
|
133
|
+
fragment_name = @query_config[:fragment_name]
|
|
134
|
+
|
|
135
|
+
if compact?
|
|
136
|
+
"#{fragments_string} query getCurrent#{type} { #{query_name} { ...#{fragment_name} } }"
|
|
137
|
+
else
|
|
138
|
+
"#{fragments_string}\n\nquery getCurrent#{type} {\n #{query_name} {\n ...#{fragment_name}\n }\n}\n"
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
116
142
|
def render_collection_query
|
|
117
143
|
type = @query_config[:model_type]
|
|
118
144
|
query_name = @query_config[:query_name]
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_shopify_graphql
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nicolò Rebughini
|
|
@@ -14,28 +14,28 @@ dependencies:
|
|
|
14
14
|
name: activemodel
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: '7.0'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - "
|
|
24
|
+
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '7.0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: activesupport
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - "
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '7.0'
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- - "
|
|
38
|
+
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '7.0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|