Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graphql 异常:收到不兼容的实例“;用户模型1“;_Graphql_Apollo_Apollo Client_Graphene Python - Fatal编程技术网

Graphql 异常:收到不兼容的实例“;用户模型1“;

Graphql 异常:收到不兼容的实例“;用户模型1“;,graphql,apollo,apollo-client,graphene-python,Graphql,Apollo,Apollo Client,Graphene Python,我正在使用石墨烯Django并试图查询一个突变 客户端是这样的: sendMessage = async () => { const mutation = `mutation sendMessage($text: String!) { createMessage(text: $text roomSlug: "${this.state.slug}") { ok

我正在使用石墨烯Django并试图查询一个突变

客户端是这样的:

sendMessage = async () => {
    const mutation = `mutation sendMessage($text: String!) {
                        createMessage(text: $text roomSlug: "${this.state.slug}") {
                          ok
                          message {
                            slug
                            createdDate
                            text
                            creator {
                              firstName
                              lastName
                              username
                              profilePictures {
                                file
                                pictureNumber
                              }
                            }
                          }
                        }
                      }
                    `;
    const { message, ok } = await apolloClient.mutate(mutation, {text: this.state.text})
        .then(result => result.data.createMessage);
class CreateMessage(graphene.Mutation):
    class Arguments:
        text = graphene.String(required=True)
        room_slug = graphene.String(required=True)

    ok = graphene.Boolean()
    message = graphene.Field(MessageType)

    def mutate(root, info, text, room_slug):
        if info.context.user.is_authenticated is False:
            raise PermissionDenied('Login required')

        ok = False
        room = get_object_or_404(models.Room, slug=room_slug)
        message = models.Message(room=room, creator=info.context.user, text=text)
        message.save()
        ok = True
        return CreateMessage(ok=ok, message=message)
服务器端是这样的:

sendMessage = async () => {
    const mutation = `mutation sendMessage($text: String!) {
                        createMessage(text: $text roomSlug: "${this.state.slug}") {
                          ok
                          message {
                            slug
                            createdDate
                            text
                            creator {
                              firstName
                              lastName
                              username
                              profilePictures {
                                file
                                pictureNumber
                              }
                            }
                          }
                        }
                      }
                    `;
    const { message, ok } = await apolloClient.mutate(mutation, {text: this.state.text})
        .then(result => result.data.createMessage);
class CreateMessage(graphene.Mutation):
    class Arguments:
        text = graphene.String(required=True)
        room_slug = graphene.String(required=True)

    ok = graphene.Boolean()
    message = graphene.Field(MessageType)

    def mutate(root, info, text, room_slug):
        if info.context.user.is_authenticated is False:
            raise PermissionDenied('Login required')

        ok = False
        room = get_object_or_404(models.Room, slug=room_slug)
        message = models.Message(room=room, creator=info.context.user, text=text)
        message.save()
        ok = True
        return CreateMessage(ok=ok, message=message)
我不知道这里出了什么问题。当我打开一个内置的graphql管理视图并通过它发送它时,这种变异就起作用了。但是,当我通过真实应用程序发送变异并抛出此错误时,它不起作用:

Exception: Received incompatible instance “User Model 1”
所以我假设这应该是一个客户端错误,但显然,这个错误来自Graphene Python,它是服务器端

我两者都有

class MessageType(DjangoObjectType):
    class Meta:
        model = models.Message

UserType代表创建者,MessageType代表消息


另外:用户类型在其他任何查询和变化中都可以正常工作。唯一不起作用的地方就是这种特殊的突变。

你找到了答案吗?