I have a graphene-django
GraphQL API that I've added custom directives and middleware in that are very similar to what's offered by graphene-django-extras
. There are several places where enum types are returned as a graphene.Int()
field, I'd like to be able to use a directive to transform that a graphene.String()
but it doesn't do that on its own. eg.
{
foo {
bar # return Int
# vs
bar @readable # return String
}
}
Is that even possible? I'm looking through the ResolvInfo
fields and there is something for the return type, but initial attempts don't work.
Edit: FWIW I don't think it matters that the API is currently developed using Python and Graphene. The question is more about whether or not GraphQL even supports this, I assume that if it does not then no language or library would make it possible.
It's not really in the spirit of graphQL to have a variable output type. So strictly speaking, you shouldn't try to do this. That being said, instead you could easily add another field for the other type, i.e.
and then just ask for the one that you want in your query.