【发布时间】:2021-09-30 23:48:52
【问题描述】:
我使用石墨烯作为后盾,并在前端使用 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)
【问题讨论】:
标签: reactjs graph typeerror apollo-client graphene-django