为什么 graphcms graphql 给我一个 403 错误?

koq*_*que 3 graphql graphcms

我在 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
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

}

`;

const 结果 = 等待请求(graphqlAPI,查询);

返回结果.postsConnection.edges;

错误:

Error: not allowed: {"response":{"errors":[{"message":"not allowed","extensions": 
Run Code Online (Sandbox Code Playgroud)

{“代码”:“403”,“路径”:[“postsConnection”,“边缘”]}}],“数据”:{“postsConnection”:{“边缘”:[]}},“状态”:200 ,"headers":{}},"request":{"query":"\n 查询 MyQuery {\n postsConnection {\n 边 {\n 节点 {\n 作者 {\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 "}}

};

小智 13

只需转到 GraphCMS 项目中的项目设置,您可以找到 Public Content API,并且有一个按钮,名称为 Yes,初始化默认值,您应该单击,它将起作用