graphql - GraphQL 错误:String 类型的变量 $customerAccessToken!提供了无效值
问题描述
我正在尝试使用用户登录 Shopify 时提供的 customerAccessToken 恢复客户。
使用 Apollo,这是我的代码:
this.apollo.mutate({
mutation: getCustomerFromToken,
variables: {
input: {
customerAccessToken: '217b9a6952c28eb4db376487a6301294' // Also tried btoa('217b9a6952c28eb4db376487a6301294')
}
},
})
这是我的 GraphQL 查询:
query getCustomerFromToken($customerAccessToken: String!) {
customer(customerAccessToken: $customerAccessToken) {
id
addresses(first: 5) {
edges {
node {
address1
address2
company
city
province
zip
country
phone
}
}
}
orders(first: 200) {
edges {
cursor
node {
id
totalPriceV2 {
amount
currencyCode
}
processedAt
orderNumber
}
}
}
}
}
这是我用来从 Shopify 检索 accessToken 的登录 GraphQL 代码:
mutation customerAccessTokenCreate($input: CustomerAccessTokenCreateInput!) {
customerAccessTokenCreate(input: $input) {
customerAccessToken {
accessToken
expiresAt
}
customerUserErrors {
code
field
message
}
}
}
解决方案
我的问题是两个方面。
- 我在查询端点上使用了突变
- 查询不使用有效负载中的输入
const payload = {
customerAccessToken: "..."
}
// NOT
const payload = {
input: {
customerAccessToken: "..."
}
}
推荐阅读
- java - 我的页面中有 3 个“愿望”链接。所以,我想获取此类链接的总数并对它们一一执行点击操作
- javascript - 当 div 覆盖另一个 div 时模拟颜色变化
- angular - 如何为离子原生视频播放器设置控件
- android - 我要安卓蓝牙广播,延迟比ADVERTISE_MODE_LOW_LATENCY少,接近苹果设备开发的10ms频率
- ios - Xcode - 为运行和测试操作设置不同的类
- scala - scala shapeless:FromRecordArgs 的默认值?
- sql - Oracle Sql Extract ID 基于分组
- sql - SQL Server - 销量第二高的查询
- vue.js - 如何从 vuejs 中的 axios 响应中访问响应数据
- docker - 如何在生产机器上使用 .NET Core 应用程序运行 Docker 容器?