Open dionyself opened 6 years ago
Yeah, I can see how that'd be a problem... Even if it could convert, a float doesn't quite capture all of the data in a timedelta.
One possibility would be to add an ObjectType wrapper that pulls out the individual parts of the timedelta
and send that, potentially with one property being the "human readable" representation.
Any other ideas?
I managed to get an human readlable for string type by using duration = graphene.String()
We probably won't need and human readable for the Float converter, so using timedelta.total_seconds() is fine... but, i think this works in py3 only
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This is a bad bot. This is still an issue.
Apologies @zeth , reopening the issue. If you have any time any help with the issue would be most appreciated.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Following
Is help still wanted for this issue? I could give it a stab if yall can tell me what you want the solution to be?
I used custom scalar for DurationField
, it has helped:
import datetime as dt
from graphene import Scalar
from graphql.language import ast
class DurationScalar(Scalar):
@staticmethod
def serialize(value):
if isinstance(value, dt.timedelta):
return str(value).zfill(8)[:-3]
@staticmethod
def parse_literal(node):
if isinstance(node, ast.StringValue):
delta = node.value.split(':')
duration = dt.timedelta(hours=delta[0], minutes=delta[1])
return duration
@staticmethod
def parse_value(value):
delta = value.split(':')
duration = dt.timedelta(hours=int(delta[0]), minutes=int(delta[1]))
return duration
hello devs. During a conversation about an issue of graphql-core @jkimbo found a possible error
https://github.com/graphql-python/graphene-django/blob/5051d3bb617ce6977eebc023c958bd10de91fe91/graphene_django/converter.py#L111-L113
raising something like
{ "message": "float() argument must be a string or a number, not 'datetime.timedelta'" }
you can check https://github.com/graphql-python/graphql-core/issues/150 for more info.