我在 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; …