Skip to content

Instantly share code, notes, and snippets.

@flavio-b
Last active November 28, 2018 07:23
Show Gist options
  • Save flavio-b/9d5582bf83938aea96dc302f6e3a6c36 to your computer and use it in GitHub Desktop.
Save flavio-b/9d5582bf83938aea96dc302f6e3a6c36 to your computer and use it in GitHub Desktop.
Adding new GraphQL client to ShopifyAPI module.
require 'that_graphql_client'
module ShopifyAPI
class GraphQLClient < GraphQLClient
SHOPIFY_GRAPHQL_ENDPOINT_TEMPLATE = "https://<MYSHOPIFY_DOMAIN>/admin/api/graphql.json"
def initialize(**args)
raise(ArgumentError, 'Must provide an shop as an argument') unless args[:shop].present?
super.tap do |client|
client.site = SHOPIFY_GRAPHQL_ENDPOINT_TEMPLATE.sub('<MYSHOPIFY_DOMAIN>', args[:shop].shopify_domain)
client.headers.merge!({'X-Shopify-Access-Token' => args[:shop].shopify_token})
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment