How to pass complex types as arguments in graphene Python

Viewed 651

I'm trying to create a query that accepts a complex argument object like so:

class Pair(graphene.ObjectType):
  x = graphene.Int()
  y = graphene.Int()

class Pairs(graphene.ObjectType):
  pairs = graphene.List(graphene.NonNull(graphene.Field(Pair, required=True)), required=True)

class Query(graphene.ObjectType):
  endpoint = graphene.Field(ResultType, pairs=graphene.Argument(Pairs, required=True))

I'm invoking it as follows in testing:

client = graphene.test.Client(graphene.Schema(query=Query))
executed = client.execute(
  """query($pairs: Pairs!) {
    endpoint(pairs: $pairs) {
      [result type goes here]
    }
  }"""

Any thoughts on what may be wrong with this approach?

1 Answers

I was able to do with the code below

class SomeFilter(graphene.InputObjectType):
    name = graphene.String()


class Query(graphene.ObjectType):
    all_somes = graphene.List(Some, options=SomeFilter())

    def resolve_all_somes(self, info, options=None):
        if options:
            if name := options.get('name'):
Related