GraphQL错误:字符串类型的变量$ 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
    }
  }
}

解决方法

我的问题有两个。

  1. 我在查询终点使用了突变
  2. 查询不在有效负载中使用输入
const payload = {
    customerAccessToken: "..."
}

// NOT

const payload = {
  input: {
    customerAccessToken: "..."
  }
}