Skip to content

Commit 7ba5072

Browse files
committed
inject prepared query.
1 parent 5da859f commit 7ba5072

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

lib/shopify_custom_data_graphql/client.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def set(key, value, bytesize)
3737
end
3838
end
3939

40+
attr_reader :lru
41+
4042
def initialize(
4143
shop_url:,
4244
access_token:,
@@ -104,8 +106,8 @@ def schema(reload_custom_schema: false, reload_admin_schema: false)
104106
def execute(query: nil, variables: nil, operation_name: nil)
105107
tracer = Tracer.new
106108
tracer.span("execute") do
107-
perform_query(query, operation_name, tracer) do |admin_query|
108-
@admin.fetch(admin_query, variables: variables)
109+
perform_query(query, operation_name, tracer) do |prepared_query|
110+
@admin.fetch(prepared_query.query, variables: variables)
109111
end
110112
end
111113
rescue ValidationError => e

lib/shopify_custom_data_graphql/prepared_query.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def to_json
5858
def perform(tracer = DEFAULT_TRACER)
5959
raise NoQueryError, "No query to execute" if query.nil?
6060

61-
raw_result = tracer.span("proxy") { yield(query, @document) }
61+
raw_result = tracer.span("proxy") { yield(self) }
6262

6363
result = if transformed?
6464
tracer.span("transform_response") do

test/shopify_custom_data_graphql/response_transformer_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,15 +808,15 @@ def fetch(fixture, document, variables: {}, operation_name: nil, schema: nil, ex
808808
errors = query.schema.static_validator.validate(query)[:errors]
809809
refute errors.any?, "Invalid custom data query: #{errors.first.message}" if errors.any?
810810
prepared_query = ShopifyCustomDataGraphQL::RequestTransformer.new(query).perform
811-
prepared_query.perform do |query_string|
811+
prepared_query.perform do |pq|
812812
file_path = "#{__dir__}/../fixtures/responses/#{fixture}.json"
813813
response = JSON.parse(File.read(file_path))
814814

815815
if expect_valid_response
816816
# validate that the cached fixture matches the request shape
817-
admin_query = GraphQL::Query.new(base_schema, query: query_string)
817+
admin_query = GraphQL::Query.new(base_schema, query: pq.query)
818818
fixture = GraphQL::ResponseValidator.new(admin_query, response, scalar_validators: SCALAR_VALIDATORS)
819-
assert fixture.valid?, "#{fixture.errors.map(&:message).join("\n")} in:\n#{query_string}"
819+
assert fixture.valid?, "#{fixture.errors.map(&:message).join("\n")} in:\n#{pq.query}"
820820
fixture.prune!.to_h
821821
else
822822
response

0 commit comments

Comments
 (0)