使用InputObjectType实例作为中继的输入

2024-04-25 14:09:58 发布

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

根据Graphene文档,如果我们要在实现relay.clientIDMutation时从用户那里获取输入,那么它需要在输入子类下面,如下所示:

class Foo(relay.clientIDMuation):
  class Input:
    arg1 = graphene.String()
    arg2 = graphene.Sring()

# the return parameters and mutate and get payload method after this

但是,我们也可以指定InputObject类型

class Bar(graphene.InputObjectType):
  arg1 = graphene.String()
  arg2 = graphene.String()

如果我们要使用普通的graphene突变对象,可以在Arguments子类中使用specify输入

class NewFoo(graphene.Mutation):
  class Arguments:
    input = Bar()

  # return arguments and mutate method after this

Bar一个InputObjectTyperelay.clientIDMutation继承而来的同时仍然能够将clientMutationID作为输入参数传递时,如何将它用于NewFoo突变中的输入属性

class NewFoo(relay.clientIDMutation):
  class Attribute:
    input = Foo()

# the return parameters and mutate and get payload method after this

注意:我已经尝试添加一个带有上述输入属性的Arguments子类,但当类从relay.clientIDMuation继承时,这不起作用


Tags: andstringreturnbarthis子类relayarguments
1条回答
网友
1楼 · 发布于 2024-04-25 14:09:58

您不需要将class Attribute:relay.clientIDMutation类一起使用

试试这个。在启动中继类之前声明该类

class Bar(graphene.InputObjectType):
   arg1 = graphene.String()
   arg2 = graphene.String()

在你的接力班里

class NewFoo(relay.clientIDMutation):
   class Input:
   inputarray = Foo()

你的变异应该是这样的

mutation{
  NewFoo(input:{
      inputarray:{
        arg1:"Hello"
        arg2:"world"
        }
      }
    )
 }

尽管您仍然无法将输入数组传递到此字段

相关问题 更多 >