【问题标题】:mutate() got multiple values for argument 'name'mutate() 为参数 'name' 获得了多个值
【发布时间】:2019-05-09 23:56:08
【问题描述】:

我想向我的 graphql 查询 createThemes。 我的 graphql 查询是:

mutation{
  createTheme(name: "qwe"){
    theme{
      id
    }
  }
}

所以它出错了:mutate() got multiple values for argument 'name'你能解决并解释为什么它会打印这样的错误。

我的代码如下:

from models import Theme as ThemeModel, Topic as TopicModel, Article as ArticleModel

    ...

class CreateTheme(graphene.Mutation):
    class Arguments:
        id = graphene.Int()
        name = graphene.String()

    theme = graphene.Field(lambda: Theme)

    def mutate(self, name):
        theme = ThemeModel(name = name)
        theme.insert()

        return CreateTheme(theme = theme)

    ...

class Mutation(graphene.ObjectType):
    create_theme = CreateTheme.Field()

    ...

schema = graphene.Schema(query=Query, mutation = Mutation)

【问题讨论】:

    标签: python flask graphql mutation


    【解决方案1】:

    [已解决] 我变了

    def mutate(self, name):
    

    到这里:

    def mutate(self, info, name):
    

    【讨论】:

    • 如果你像我一样,我根据 PyCharm 的建议添加了一个 @staticmethod 装饰器(这也删除了 self 参数)。删除 @staticmethod 并添加 self 参数,为我修复它:\
    猜你喜欢
    • 2018-03-12
    • 2021-06-13
    • 2018-11-18
    • 2017-12-23
    • 1970-01-01
    • 2022-11-06
    • 2019-07-05
    • 2019-02-08
    相关资源
    最近更新 更多