Class: ShopifyAPI::Clients::Graphql::Client

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/shopify_api/clients/graphql/client.rb

Direct Known Subclasses

Admin, Storefront

Instance Method Summary collapse

Constructor Details

#initialize(session:, base_path:, api_version: nil) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/shopify_api/clients/graphql/client.rb', line 11

def initialize(session:, base_path:, api_version: nil)
  @http_client = T.let(HttpClient.new(session: session, base_path: base_path), HttpClient)
  @api_version = T.let(api_version || Context.api_version, String)
  if api_version
    if api_version == Context.api_version
      Context.logger.debug("Graphql client has a redundant API version override "\
        "to the default #{Context.api_version}")
    else
      Context.logger.debug("Graphql client overriding default API version "\
        "#{Context.api_version} with #{api_version}")
    end
  end
end

Instance Method Details

#query(query:, variables: nil, headers: nil, tries: 1, response_as_struct: Context.response_as_struct, debug: false) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/shopify_api/clients/graphql/client.rb', line 35

def query(
  query:,
  variables: nil,
  headers: nil,
  tries: 1,
  response_as_struct: Context.response_as_struct,
  debug: false
)
  body = { query: query, variables: variables }
  search_params = debug ? "?debug=true" : ""

  @http_client.request(
    HttpRequest.new(
      http_method: :post,
      path: "#{@api_version}/graphql.json#{search_params}",
      body: body,
      query: nil,
      extra_headers: headers,
      body_type: "application/json",
      tries: tries,
    ),
    response_as_struct: response_as_struct || false,
  )
end