答:我想明白了。后续代码很旧,GraphQL API有更新。我不得不去他们的API Playground重新编写代码。
我正在使用www.example.com作为后端使用Nextjs制作博客hygraph.com。我试图让它在您点击时可以看到帖子,但它突然停止了对我的工作。如果您确实需要它,这里是我的整个代码:https://github.com/DeviousWings/blog-app
我在这个程序中使用了这个后续程序:https://www.youtube.com/watch?v=HYv55DhgTuA我的混乱似乎是在1:46:40马克。
如果你需要更多的信息,让我知道,我会把一个“编辑”在前面。
下面是错误消息:
Server Error
Error: [line: 1] field 'excerpt' is not defined in 'Post':
{"response":{"errors":[{"message":
"[line: 1] field 'excerpt' is not defined in 'Post'"}],
"data":null,"extensions":"requestId":"clgir0yw21ztz0blki9cm5z9o"},
"status":400,"headers":{}},"request":
query GetPostDetails($slug : String!) {
post(where: {slug: $slug}) {
author{
name
bio
photo {
url
}
}
createdAt
slug
title
excerpt
featuredImage {
url
}
categories {
name
slug
}
content {
raw
}
}
}
`;
",
"variables":{"slug":"space-cockpit"}}}
下面是混乱的根源:
services\index.js (109:17) @ async getPostDetails
107 |
108 |
> 109 | const result = await request(graphqlAPI, query, { slug });
| ^
110 |
111 | return result.post;
112 | };
以下是源代码所在的完整代码(blog-app\services\index.js):
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
name
id
photo {
url
}
}
createdAt
slug
title
exerpt
featuredImage {
url
}
categories {
name
slug
}
}
}
}
}
`;
const result = await request(graphqlAPI, query)
return result.postsConnection.edges;
};
export const getCategories = async () => {
const query = gql`
query GetGategories {
categories {
name
slug
}
}
`;
const result = await request(graphqlAPI, query);
return result.categories;
}
export const getRecentPosts = async () => {
const query = gql `
query GetPostDetails() {
posts(
orderBy: createdAt_ASC
last: 3
) {
title
featuredImage {
url
}
createdAt
slug
}
}
`
const result = await request(graphqlAPI, query)
return result.posts;
};
export const getPostDetails = async (slug) => {
const query = gql`
query GetPostDetails($slug : String!) {
post(where: {slug: $slug}) {
author{
name
bio
photo {
url
}
}
createdAt
slug
title
excerpt
featuredImage {
url
}
categories {
name
slug
}
content {
raw
}
}
}
`;
const result = await request(graphqlAPI, query, { slug });
return result.post;
};
export const getSimilarPosts = async (categories, slug) => {
const query = gql`
query GetPostDetails($slug: String!, $categories: [String!]) {
posts(
where: {slug_not: $slug, AND: {categories_some: {slug_in: $categories}}}
last: 3
) {
title
featuredImage {
url
}
createdAt
slug
}
}
`;
const result = await request(graphqlAPI, query, { slug, categories });
return result.posts;
};
我的模特:
CommentModel
Post Model
我不擅长调试,但我的console.log没有拾取任何东西。
1条答案
按热度按时间alen0pnh1#
弄明白了。后续的是旧的,GraphQL API有一个更新。我不得不去他们的API Playground重新做代码。