Python石墨烯突变是不起作用的

2024-06-15 01:55:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Graphql和Python也是新手。在

所以当我在开发一个lil项目时,我遇到了一个关于突变的问题:

class User(graphene.ObjectType):
    id = graphene.ID(required=False)
    username = graphene.String()
    last_login = graphene.DateTime(required=False)

class CreateUser(graphene.Mutation):

    class Arguments:
        username = graphene.String()

    user = graphene.Field(User)

    def mutate(self, info, username):
        user = User(username=username)
        return CreateUser(user=user)

class Mutations(graphene.ObjectType):
    create_user = CreateUser.Field()

schema = graphene.Schema(mutation=Mutations)

我给邮递员打了个电话:

{ "mutation": "{ createUser(username: 'User test') { user { username } } }" }

我的标题:

Content-Type:application/json

我的回答是null

我不知道我的问题是实施还是我的要求。在

-------------已编辑----------------------------- 我只是在我的代码中修改了一些东西,现在我有了一个查询,它工作了,我直接在代码中实现了一个简单的请求,它也起作用了

我刚刚做到了:

^{pr2}$

因此,当我在Postman中调用查询时,它也起作用:

{ "query": "{ allUsers {username lastLogin} }" }

和标题:

Content-Type:application/json

我不明白为什么在邮递员中查询有效而变异无效。在


Tags: false标题field邮递员stringrequiredusernameclass