
Security News
CISA’s 2025 SBOM Guidance Adds Hashes, Licenses, Tool Metadata, and Context
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
shopify_api-graphql-tiny
Advanced tools
Lightweight, no-nonsense, Shopify GraphQL Admin API client with built-in pagination and retry.
require "shopify_api/graphql/tiny"
gql = ShopifyAPI::GraphQL::Tiny.new("my-shop", token)
# Automatically retried
result = gql.execute(<<-GQL, :id => "gid://shopify/Customer/1283599123")
query findCustomer($id: ID!) {
customer(id: $id) {
id
tags
metafields(first: 10 namespace: "foo") {
edges {
node {
id
key
value
}
}
}
}
}
GQL
customer = result["data"]["customer"]
p customer["tags"]
p customer.dig("metafields", "edges", 0, "node")["value"]
updates = { :id => customer["id"], :tags => customer["tags"] + %w[foo bar] }
# Automatically retried as well
result = gql.execute(<<-GQL, :input => updates)
mutation customerUpdate($input: CustomerInput!) {
customerUpdate(input: $input) {
customer {
id
}
userErrors {
field
message
}
}
}
GQL
p result.dig("data", "customerUpdate", "userErrors")
In addition to built-in request retry ShopifyAPI::GraphQL::Tiny
also builds in support for pagination.
Using pagination requires you to include the Shopify PageInfo
object
in your queries and wrap them in a function that accepts a page/cursor argument.
The pager's #execute
is like the non-paginated #execute
method and accepts additional, non-pagination query arguments:
pager.execute(query, :foo => 123)
And it accepts a block which will be passed each page returned by the query:
pager.execute(query, :foo => 123) do |page|
# do something with each page
end
after
PaginationTo use after
pagination, i.e., to paginate forward, your query must:
PageInfo
's hasNextPage
and endCursor
fieldsFor example:
FIND_ORDERS = <<-GQL
query findOrders($after: String) {
orders(first: 10 after: $after) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
id
email
}
}
}
}
GQL
pager = gql.paginate # This is the same as gql.paginate(:after)
pager.execute(FIND_ORDERS) do |page|
orders = page.dig("data", "orders", "edges")
orders.each do |order|
# ...
end
end
By default it is assumed your GraphQL query uses a variable named $after
. You can specify a different name using the :variable
option:
pager = gql.paginate(:after, :variable => "yourVariable")
before
PaginationTo use before
pagination, i.e. to paginate backward, your query must:
PageInfo
's hasPreviousPage
and startCursor
fields:before
argument to #paginate
For example:
FIND_ORDERS = <<-GQL
query findOrders($before: String) {
orders(last: 10 before: $before) {
pageInfo {
hasPreviousPage
startCursor
}
edges {
node {
id
email
}
}
}
}
GQL
pager = gql.paginate(:before)
pager.execute(FIND_ORDERS) do |page|
# ...
end
By default it is assumed your GraphQL query uses a variable named $before
. You can specify a different name using the :variable
option:
pager = gql.paginate(:before, :variable => "yourVariable")
By default ShopifyAPI::GraphQL::Tiny
will use the first pageInfo
block with a next or previous page it finds
in the GraphQL response. If necessary you can specify an explicit location for the pageInfo
block:
pager = gql.paginate(:after => %w[some path to it])
pager.execute(query) { |page| }
pager = gql.paginate(:after => ->(data) { data.dig("some", "path", "to", "it") })
pager.execute(query) { |page| }
The "data"
and "pageInfo"
keys are automatically added if not provided.
See the docs for more information.
cp env.template .env
and fill-in .env
with the missing values. This requires a Shopify store.
The gem is available as open source under the terms of the MIT License.
Made by ScreenStaring
FAQs
Unknown package
We found that shopify_api-graphql-tiny demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.