当我从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
}
}
}并通过“购物GraphiQL应用”运行它,变异就成功创建了。
我不确定如何使用Ruby和Ruby (请注意,我对shopify_api和GraphQL都是新手,所以我可能缺少一些非常基本的东西,但我在任何地方都找不到答案)。
我尝试了以下操作:
@@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'):这让我看了一下query gem的GraphQL类,希望找到一个“变异”方法来代替“shopify_api”方法,但是没有。
我也不能从shopify_api使用的graphql-client gem中找出它--自述文件中没有突变的例子。
我遗漏了什么?
谢谢,
-Louise
发布于 2019-12-20 16:49:56
我在购物论坛上得到了答案-我只需要在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
}
}
}
GRAPHQLhttps://stackoverflow.com/questions/59405430
复制相似问题