我使用石墨烯作为后端,并在前端使用apollo进行反应,但是当尝试发出一个只返回一个对象的请求时,它给出了以下错误
react中的代码是
import React from 'react'
import { useParams } from 'react-router-dom';
import { gql, useQuery } from '@apollo/client';
const Post = (props) => {
const { id } = useParams();
console.log(id);
const [loading, error, data] = useQuery(GET_POST, {
variables: {
postId: id
}
})
if (loading) return null;
if (error) return `Error! ${error}`;
return (
<div>
Post
</div>
)
}
const GET_POST = gql`
query IdPost($postId: ID!){
idPost(postId:$postId){
id
user{
username
email
}
title
body
image
createdAt
updatedAt
published
}
}
`;
export default Post
我不知道这是为什么,这里我也留下了我在石墨烯中用于该请求的代码
class Query(graphene.ObjectType):
all_posts = graphene.List(PostType)
id_post = graphene.Field(PostType, postId=graphene.ID())
def resolve_all_posts(root, info):
return Post.objects.filter(published=True)
def resolve_id_post(root, info, postId):
return Post.objects.get(id=postId)
发布于 2021-07-24 08:34:10
我相信是这样的
const {loading, error, data} = useQuery
不
const [loading, error, data] = useQuery
https://stackoverflow.com/questions/68506142
复制相似问题