我在我的应用程序中使用shopify-api-node (v3.2.0)中的node.js来验证客户登录,以及购物的其他功能。根据shopify文档(https://shopify.dev/docs/storefront-api/reference/mutation/customeraccesstokencreate),我正在使用GraphQL访问shopify API。我的代码如下所示:
const Shopify = require('shopify-api-node');
const shopify = new Shopify({
shopName: process.env.SHOPIFY_DOMAIN_NAME,
apiKey: process.env.SHOPIFY_API_KEY,
password: process.env.SHOPIFY_API_KEY_PASSWORD
});
const query = `mutation {
customerAccessTokenCreate (input: {
email: "user@mail.com",
password: "password123"
}
)
{
customerAccessToken {
accessToken
expiresAt
}
customerUserErrors {
code
field
message
}
}
}`;
shopify
.graphql(query)
.then((output) => {
console.log(output);
})
.catch((err) => {
console.error(err)
});在此之后,我得到以下错误:-
Error: Field 'customerAccessTokenCreate' doesn't exist on type 'Mutation'
at got.then (/Users/admin/Documents/Code/shopify-node-app/node_modules/shopify-api-node/index.js:239:19)
at process._tickCallback (internal/process/next_tick.js:68:7)
locations: [ { line: 2, column: 5 } ],
path: [ 'mutation', 'customerAccessTokenCreate' ],
extensions:
{ code: 'undefinedField',
typeName: 'Mutation',
fieldName: 'customerAccessTokenCreate' }就连我也从邮递员那里得到了同样的东西。
任何帮助都将不胜感激。
发布于 2020-02-19 01:08:23
GraphQL有两种类型:
storefront管理员- https://shopify.dev/docs/storefront-api/reference
虽然它们看起来很相似,但strorefront的限制更多,但可以在前端使用,而admin one的方法和功能更丰富,但不能安全地在字体端使用。
您尝试制作的文档和方法引用的是Storefront应用编程接口,但您使用的包是用于管理GraphQL应用编程接口的。
如果要发出storefront请求,但Admin API GraphQL允许进行更多自定义,则可以通过storefrontAccessToken方法创建storefront访问令牌。
所以你需要确保你使用的是正确的API。
如果你计划使用storefront应用程序接口,你不应该使用NodeJS,只需要创建一个私人应用程序(从管理->应用程序->私有应用程序),它将为你提供一个商店前端访问令牌(如果你在底部启用它并选择合适的作用域),可以直接在前端使用。
如果你计划使用Admin API,你将需要创建一个公共应用程序并托管它,然后你可以使用NodeJS并通过Shopify中的代理传递信息。
摘要
在使用Admin API的库时,您正在向Storefront API发出请求。
https://stackoverflow.com/questions/60281506
复制相似问题