Skip to content

Instantly share code, notes, and snippets.

@forsbergplustwo
Created October 22, 2018 11:41
Show Gist options
  • Save forsbergplustwo/d88c790b77ad7063b1a1080fbf559cc3 to your computer and use it in GitHub Desktop.
Save forsbergplustwo/d88c790b77ad7063b1a1080fbf559cc3 to your computer and use it in GitHub Desktop.
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
@forsbergplustwo
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment