Skip to content

Commit a55ce4d

Browse files
authored
Fix some capabilities
fix some issues.
2 parents 5ff3a54 + e825546 commit a55ce4d

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

lib/shopify_custom_data_graphql/custom_data_catalog/metafield_definition.rb

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,7 @@ class CustomDataCatalog
1616
}
1717
|
1818

19-
MetafieldDefinition = Struct.new(
20-
:key,
21-
:type,
22-
:namespace,
23-
:description,
24-
:validations,
25-
:owner_type,
26-
:schema_namespace,
27-
keyword_init: true
28-
) do
19+
class MetafieldDefinition
2920
class << self
3021
def from_graphql(metafield_def)
3122
new(
@@ -39,8 +30,21 @@ def from_graphql(metafield_def)
3930
end
4031
end
4132

33+
attr_reader :key, :type, :namespace, :description, :validations, :owner_type
34+
attr_accessor :schema_namespace
35+
36+
def initialize(key:, type:, namespace:, description:, validations:, owner_type:)
37+
@key = key
38+
@type = type
39+
@namespace = namespace
40+
@description = description
41+
@validations = validations
42+
# need to handle irregulars...
43+
@owner_type = owner_type&.underscore&.upcase || "METAOBJECT"
44+
end
45+
4246
def reference_key
43-
@reference_key ||= [namespace, key].tap(&:compact!).join(".")
47+
@reference_key ||= owner_type == "METAOBJECT" ? key : [namespace, key].tap(&:compact!).join(".")
4448
end
4549

4650
def schema_key

lib/shopify_custom_data_graphql/prepared_query.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ def to_h
2121

2222
attr_reader :query, :transforms
2323

24-
def initialize(params)
24+
def initialize(params, document: nil)
2525
@query = params["query"]
2626
@transforms = params["transforms"] || EMPTY_HASH
27+
@document = document
2728
end
2829

2930
def as_json
@@ -43,7 +44,7 @@ def perform(tracer = DEFAULT_TRACER, source_query: nil)
4344
query = source_query && base_query? ? source_query : @query
4445
raise ArgumentError, "A source_query is required with empty transformations" if query.nil?
4546

46-
raw_result = tracer.span("proxy") { yield(query) }
47+
raw_result = tracer.span("proxy") { yield(query, @document) }
4748

4849
result = if @transforms.any?
4950
tracer.span("transform_response") do

lib/shopify_custom_data_graphql/request_transformer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def transforms
3434
end
3535

3636
def to_prepared_query
37-
PreparedQuery.new({ "query" => query, "transforms" => transforms })
37+
PreparedQuery.new({ "query" => query, "transforms" => transforms }, document: @document)
3838
end
3939
end
4040

0 commit comments

Comments
 (0)