Skip to content

Instantly share code, notes, and snippets.

@richter-alex
Created August 13, 2019 19:09
Show Gist options
  • Save richter-alex/d41c79be52dd0986c9215f0df045e9cb to your computer and use it in GitHub Desktop.
Save richter-alex/d41c79be52dd0986c9215f0df045e9cb to your computer and use it in GitHub Desktop.
require 'shopify_api'
require 'json'
require 'pry'
session = ShopifyAPI::Session.new(domain: SHOP, token: YOUR_ACCESS_TOKEN, api_version: '2019-07')
ShopifyAPI::Base.activate_session(session)
client = ShopifyAPI::GraphQL.new
tags_query_string = %(
query {
shop {
orderTags(first: 250) {
edges {
node
}
}
}
}
)
TAGS_QUERY = client.parse tags_query_string
tags_result = client.query(TAGS_QUERY)
tags = tags_result.data.shop.order_tags.edges.map {|e| e.node}
orders_query = tags.map { |t| "-tag:#{t.to_json}" }.join(' AND ')
cursor = nil
loop do
print '.'
order_query_string = %(
query {
orders(
first: 250
after: #{cursor.to_json}
query: #{orders_query.to_json}
) {
pageInfo {
hasNextPage
}
edges {
cursor
node {
id
}
}
}
}
)
ORDER_QUERY = client.parse order_query_string
result = client.query(ORDER_QUERY)
cursor = result.data.orders.edges.last.try { |e| e.cursor }
if cursor.nil?
puts "\n"
puts order_query_string
puts JSON.pretty_generate(result.original_hash)
break
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment