Created
October 22, 2018 11:41
-
-
Save forsbergplustwo/d88c790b77ad7063b1a1080fbf559cc3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
CollectionsQuery = <<~GRAPHQL | |
{ | |
shop { | |
name | |
} | |
collections(first: 15, sortKey: UPDATED_AT, reverse: true) { | |
edges { | |
node { | |
id | |
title | |
handle | |
image { | |
id | |
transformedSrc(maxWidth: 80) | |
originalSrc | |
} | |
description(truncateAt: 100) | |
products(first: 6, sortKey: COLLECTION_DEFAULT, reverse: true) { | |
edges { | |
node { | |
id | |
handle | |
title | |
vendor | |
description(truncateAt: 100) | |
priceRange { | |
minVariantPrice { | |
amount | |
} | |
maxVariantPrice { | |
amount | |
} | |
} | |
onlineStorePreviewUrl | |
images(first: 1, sortKey: POSITION) { | |
edges { | |
node { | |
id | |
transformedSrc(maxWidth: 80) | |
originalSrc | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
GRAPHQL | |
# RUNS IN BEFORE FILTER | |
def setup_graphql | |
@client = Graphlient::Client.new( | |
"https://#{@shopify_shop.myshopify_domain}/admin/api/graphql.json", | |
schema_path: "#{Rails.root}/lib/assets/graphql_schema.json", | |
headers: { | |
'X-Shopify-Access-Token' => "#{@shop.token}" | |
} | |
) | |
end | |
def collections | |
response = @client.query(CollectionsQuery) | |
@collections = response.data.collections.edges | |
respond_to do |format| | |
format.json { @collections } | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My issue is that my response times sometimes get a real slow request, taking about 5 seconds. I've noticed this is about the same amount of time it takes to load the schema on every request using HTTP instead of the saved json. This is of course in development environment, but loading from disk should not rely on caching to be enabled (from my understanding).
Would love to know how I can setup the Graphlient to not be reloaded on every request, but instead just switch out which myshopify.com store it points to.
Any recommendations?