当我从https://help.shopify.com/en/api/guides/billing-api/implement-your-business-model#implement-the-appsu ...复制下面的示例时:
appSubscriptionCreate(
name: "Super Duper Recurring Plan"
returnUrl: "http://super-duper.shopifyapps.com"
lineItems: [{
plan: {
appRecurringPricingDetails: {
price: { amount: 10.00, currencyCode: USD }
}
}
}]
) {
userErrors {
field
message
}
confirmationUrl
appSubscription {
id
}
}
}
并通过“ Shopify GraphiQL App”运行它,成功创建了该突变。
我不确定如何使用Ruby和shopify_api gem(请注意,我对Ruby和GraphQL还是Ruby的新手,所以我可能缺少了一些非常基本的东西,但是我找不到它在任何地方回答)。
我尝试了以下操作:
@@client = ShopifyAPI::GraphQL.new
PAYMENT_MUTATION = @@client.parse <<-'GRAPHQL'
{
mutation {
appSubscriptionCreate(
name: "Super Duper Recurring Plan"
returnUrl: "http://super-duper.shopifyapps.com"
lineItems: [{
plan: {
appRecurringPricingDetails: {
price: {
amount: 10.00,
currencyCode: USD
}
}
}
}]
) {
userErrors {
field
message
}
confirmationUrl
appSubscription {
id
}
}
}
}
GRAPHQL
def initialize
@result = @@client.query(PAYMENT_MUTATION)
end
def confirmationUrl
@result.data.appSubscriptionCreate.confirmationUrl
end
end
尽管出现以下错误:
GraphQL::Client::ValidationError (Field 'mutation' doesn't exist on type 'QueryRoot'):
我尝试跳过突变部分,但随后我得到了错误:
GraphQL::Client::ValidationError (Field 'appSubscriptionCreate' doesn't exist on type 'QueryRoot'):
这使我看了一看shopify_api gem的GraphQL类,希望找到一种可以使用的“变异”方法代替“查询”方法,但是没有。
我不能从shopq_api正在使用的graphql-client gem中弄清楚-自述文件中没有突变示例。
我想念什么?
谢谢
-路易丝
答案 0 :(得分:0)
在Shopify论坛上得到了答案-我只需要删除PAYMENT_MUTATION中的外部{}。
PAYMENT_MUTATION = @@client.parse <<-'GRAPHQL'
mutation {
appSubscriptionCreate(
name: "Super Duper Recurring Plan"
returnUrl: "http://super-duper.shopifyapps.com"
lineItems: [{
plan: {
appRecurringPricingDetails: {
price: {
amount: 10.00,
currencyCode: USD
}
}
}
}]
) {
userErrors {
field
message
}
confirmationUrl
appSubscription {
id
}
}
}
GRAPHQL