Skip to content

resolve_ methods on nested objects #44

@sedlar

Description

@sedlar

Is it possible to use resolve_ method on nested objects like in following updated aiohttp example code?

import random
import asyncio
import graphene


class Query(graphene.ObjectType):
    base = graphene.String()


class RandomType(graphene.ObjectType):
    seconds = graphene.Int()
    random_int = graphene.Int()

  async def resolve_random_int(_, __):
    return random.randint(0, 500)


class Subscription(graphene.ObjectType):
    random_int = graphene.Field(RandomType)

    async def resolve_random_int(root, info):
        i = 0
        while True:
            yield RandomType(seconds=i)
            await asyncio.sleep(1.)
            i += 1


schema = graphene.Schema(query=Query, subscription=Subscription)

I'm getting following error message

{
  "id": 26,
  "type": "data",
  "payload": {
    "data": {
      "random_int": null
    },
  "errors": [
     {
       "message": "int() argument must be a string, a bytes-like object or a number, not 'AnonymousObservable'"
     }
]}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions