我在 graphcms 中创建了以下查询,它在 graphql playground 中工作,但是当我将查询传输到我的 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
}
}
}
}
`;
const result = await request(graphqlAPI, query);
返回结果.postsConnection.edges;
错误:
Error: not allowed: {"response":{"errors":[{"message":"not allowed","extensions":
{"code":"403","path":["postsConnection","edges"]}}],"data":{"postsConnection":{"edges":[]}},"status ":200,"headers":{}},"request":{"query":"\n query MyQuery {\n postsConnection {\n edges {\n node {\n author {\n bio\n id\n 名称\n 照片 {\n url\n }\n 帖子 {\n 类别 {\n 名称\n slug\n }\n }\n }\n 创建于\n slug\n 标题\n 摘录\n featureImage {\n 网址\n }\n }\n }\n }\n }\n\n "}}
};
最佳答案
只需在 GraphCMS 的项目中转到项目设置,您可以找到 Public Content API 并且有一个名称为的按钮 是的,初始化默认值,您应该单击,它会起作用
https://stackoverflow.com/questions/70294008/
相关文章:
rust - 在 ".map(|x| *x)"之前是否有更好的 ".collect()"替代品?
phpunit - 在 php 8.1.0 上使用 phpunit 9.4 捕获警告、通知和弃用
java - 当我们调用 function(2) 时,为什么这个函数返回 83 而不是 5?
python - 使用正则表达式 python 删除德语中的女性结尾
go - 为什么 DefaultMask() 方法在 Golang 中有一个 IP 类型的接收者?
php - 为什么php artisan make :factory not Generating
amazon-web-services - Docker 推送错误保存凭据 : error stor