我在graphcms中创建了以下查询,它在graphql操场上工作,但是当我将查询转移到我的react代码并尝试访问graphcms时,我会得到一个403错误,如下所示。
查询:
import { request, gql } from 'graphql-request';
const graphqlAPI = process.env.NEXT_PUBLIC_GRAPHCMS_ENDPOINT;
export const getPosts = async () => {
const query = gql`
query MyQuery {
postsConnection {
edges {
node {
author {
bio
id
name
photo {
url
}
post {
categories {
name
slug
}
}
}
createdAt
slug
title
excerpt
featureImage {
url
}
}
}
}}
` `;
结果=等待请求(graphqlAPI,查询);
返回result.postsConnection.edges;
错误:
Error: not allowed: {"response":{"errors":[{"message":"not allowed","extensions": {“代码”:“403”,“路径”:“postsConnection”,“边”}},“数据”:{“postsConnection”:{“postsConnection”:[]},“状态”:200,“标头”:{},“请求”:{“查询”:“\n查询MyQuery {\n postsConnection {\n边{\n节点{\n作者{\n bio\n id\n name\n照片{\n url\n }\n post {\n”类别{\n )名称\n段塞}\n }\n }\n \n段塞\n标题\n摘录\n featureImage {\n }}n} }\n }\n“}
};
发布于 2022-01-13 21:07:04
只需转到GraphCMS项目中的项目设置,就可以找到,并有一个按钮,名称是是,初始化默认值,您应该单击它,它会工作的
发布于 2021-12-10 06:58:17
在试图绘制图形时,我也收到了类似的错误:
Error: not allowed: {"response":{"errors":[{"message":"not allowed","extensions":{"code":"403","path":["blogPosts"]}}],"data":{"blogPosts":[]},"status":200,"headers":{}},"request":{"query":"\n {\n blogPosts {\n id,\n title\n }\n }\n "}}。
我发现对我有用的是给我永久的Auth令牌(PAT)添加“读取”权限。
https://stackoverflow.com/questions/70294008
复制相似问题