Class: ShopifyAPI::Clients::Graphql::Storefront

Inherits:
Client
  • Object
show all
Defined in:
lib/shopify_api/clients/graphql/storefront.rb

Instance Method Summary collapse

Constructor Details

#initialize(shop, storefront_access_token = nil, private_token: nil, public_token: nil, api_version: nil) ⇒ Storefront

Returns a new instance of Storefront.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/shopify_api/clients/graphql/storefront.rb', line 17

def initialize(shop, storefront_access_token = nil, private_token: nil, public_token: nil, api_version: nil)
  unless storefront_access_token.nil?
    warning = "      DEPRECATED: Use the named parameters for the Storefront token instead of passing\n      the public token as the second argument. Also, you may want to look into using\n      the Storefront private access token instead:\n      https://shopify.dev/docs/api/usage/authentication#getting-started-with-private-access\n    WARNING\n    ShopifyAPI::Logger.deprecated(warning, \"15.0.0\")\n  end\n\n  session = Auth::Session.new(\n    id: shop,\n    shop: shop,\n    access_token: \"\",\n    is_online: false,\n  )\n  super(session: session, base_path: \"/api\", api_version: api_version)\n  @storefront_access_token = T.let(T.must(private_token || public_token || storefront_access_token), String)\n  @storefront_auth_header = T.let(\n    private_token.nil? ? \"X-Shopify-Storefront-Access-Token\" : \"Shopify-Storefront-Private-Token\",\n    String,\n  )\nend\n"

Instance Method Details

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



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/shopify_api/clients/graphql/storefront.rb', line 52

def query(
  query:,
  variables: nil,
  headers: {},
  tries: 1,
  response_as_struct: Context.response_as_struct,
  debug: false
)
  T.must(headers).merge!({ @storefront_auth_header => @storefront_access_token })
  super(query: query, variables: variables, headers: headers, tries: tries,
            response_as_struct: response_as_struct, debug: debug)
end