ruby-on-rails - 如何使用 Ruby shopify_api gem 创建 GraphQL appSubscriptionCreate 突变?
问题描述
当我从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 的新手,所以这可能是我缺少的一些非常基本的东西,但我无法在任何地方找到答案) .
我尝试了以下操作:
@@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 类,希望找到一个“变异”方法来代替“查询”方法,但没有。
我无法从 shopify_api 正在使用的 graphql-client gem 中弄清楚 - 自述文件中没有突变示例。
我错过了什么?
谢谢,
-路易丝
解决方案
在 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
推荐阅读
- android-recyclerview - TextView 在 RecyclerView 中仅显示第一个字母
- scala - 如何使用 µPickle 序列化通用案例类?
- azure - 如何使用 Go SDK 在 Azure 存储中列出共享
- javascript - 使用 ajax 操作更新模态内容而不在用户操作后关闭它 - Odoo 前端
- batch-file - 重命名多个文件添加前缀
- angular - Angular 组件未获得 Google Chart 参考
- dart - Android 之类的日历,用于 dart 中的日期计算
- cypress - 无法使用 cypressJS 请求路由
- c# - 在嵌套循环中获取对象
- python - 如何在列表正在填充且任务尚未完成时通过views.py访问tasks.py中的列表的值?