【发布时间】:2021-05-10 19:56:20
【问题描述】:
我正在尝试使用 Sinatra 对 Shopify 商店进行基本的 GraphQL 查询。有人可以帮我弄清楚我做错了什么吗?我查看了他们的 API 来做到这一点:
require 'shopify_api'
require 'sinatra'
class App < Sinatra::Base
get '/' do
shop = 'xxxx.myshopify.com'
token = 'shpat_xxxxxxxxxxxxxxxxxxxxxx'
session = ShopifyAPI::Session.new(domain: shop, token: token, api_version: "2021-04")
ShopifyAPI::Base.activate_session(session)
ShopifyAPI::GraphQL.initialize_clients
client = ShopifyAPI::GraphQL.client
SHOP_NAME_QUERY = client.parse <<-'GRAPHQL'
{
shop {
name
}
}
GRAPHQL
result = client.query(SHOP_NAME_QUERY)
result.data.shop.name
end
end
这给出了这个错误,但我不想使用 Rake 或 Rails。是否可以使用 Ruby 对 Shopify 进行 GraphQL 查询?
ShopifyAPI::GraphQL::InvalidClient at /
Client for API version 2021-04 does not exist because no schema file exists at `shopify_graphql_schemas/2021-04.json`. To dump the schema file, use the `rake shopify_api:graphql:dump` task
【问题讨论】:
标签: ruby graphql shopify sinatra shopify-app