1
It turns out you do not have to write a customer resolver, but instead can just declare the type of the Django field, like so:
class ToyType(DjangoObjectType):
price = graphene.Float()
class Meta:
model = Toy
fields = ('name', 'price')
In this way, the resolver will return price as a Float. If you do not explicitly declare the type, the graphene default is to return the django Decimal field as a string.
0
To convert the decimal value to a float, use a custom resolver as shown.
class ToyType(DjangoObjectType):
class Meta:
model = Toy
fields = ('name', 'price')
price = graphene.Float()
def resolve_price(self, info):
return float(self.price)
- [Answered ]-Update javascripts that are cached in the Chrome browser
- [Answered ]-OSError on uploading files in Django
- [Answered ]-How can i use variable in django while accessing models
- [Answered ]-Combine built-in tags in templates with variables
- [Answered ]-Loading static files in django
Source:stackexchange.com