我如何使用Ruby shopify_api gem创建GraphQL appSubscriptionCreate突变?

问题描述 投票:0回答:1

[当我从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类,希望找到要使用的“变异”方法而不是“查询”方法,但是没有。

我无法从graphql-client gem判断出shopify_api是否使用了这两种-自述文件中没有突变示例。

我想念什么?

谢谢,

-路易丝

[当我从https://help.shopify.com/en/api/guides/billing-api/implement-your-business-model#implement-the-appsu ...复制以下示例时:appSubscriptionCreate(名称: “超级重复操作重复出现...

ruby-on-rails ruby graphql shopify shopify-app
1个回答
0
投票

在Shopify论坛上得到了答案-我只需要删除PAYMENT_MUTATION中的外部{}。

© www.soinside.com 2019 - 2024. All rights reserved.