Created
February 1, 2021 15:49
-
-
Save daniel-sim/e8eee982b0e90dd3b74fc66eb568872c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "graphql/client" | |
require "http_client" | |
module ShopifyPartnerAPI | |
class << self | |
delegate :parse, :query, to: :client | |
def client | |
initialize_client_cache | |
cached_client = @_client_cache | |
if cached_client != nil | |
cached_client | |
else | |
initialize_client | |
@_client_cache | |
end | |
end | |
def initialize_client | |
initialize_client_cache | |
http = ShopifyPartnerAPI::HTTPClient.new | |
# So the schema is not requested every time the client is initialized we store it on disk. | |
# If the schema changes, run GraphQL::Client.dump_schema(http, "config/partner-api-schema.json") | |
GraphQL::Client.dump_schema(http, "config/partner-api-schema.json") unless File.exists?("config/partner-api-schema.json") | |
schema = GraphQL::Client.load_schema("config/partner-api-schema.json") | |
client = GraphQL::Client.new(schema: schema, execute: http) | |
@_client_cache = client | |
end | |
private | |
def initialize_client_cache | |
@_client_cache ||= nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment