question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Decimal type

See original GitHub issue

I’ve been using my own implementation of a Decimal type – maybe it should be included as a standard type?

from graphene.types import Scalar
from graphql.language import ast

class Decimal(Scalar):
    """
    The `Decimal` scalar type represents a python Decimal.
    """
    @staticmethod
    def serialize(dec):
        assert isinstance(dec, decimal.Decimal), (
            'Received not compatible Decimal "{}"'.format(repr(dec))
        )
        return str(dec)
    
    @staticmethod
    def parse_value(value):
        return decimal.Decimal(value)
    
    @classmethod
    def parse_literal(cls, node):
        if isinstance(node, ast.StringValue):
            return cls.parse_value(node.value)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
picturedotscommented, Apr 9, 2018

Ok, I will take a crack at it when I have a chance. I’ll have a look at the existing tests for other types for some examples.

1reaction
jkimbocommented, Sep 22, 2019

(also it is there in the API documentation at least! https://docs.graphene-python.org/en/latest/api/#graphene-scalars)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Decimal Data Type - Visual Basic | Microsoft Learn
The Decimal data type provides the greatest number of significant digits for a number. It supports up to 29 significant digits and can ......
Read more >
Decimal data type - Wikipedia
Language support​​ C# has a built-in data type 'decimal', consisting of 128-bit resulting in 28-29 significant digits. It has an approximate Range of...
Read more >
DECIMAL Data Type (Impala 3.0 or higher only)
The Impala DECIMAL type does not support negative values for precision. Parent topic: Data Types.
Read more >
DECIMAL data type
DECIMAL data type ... DECIMAL provides an exact numeric in which the precision and scale can be arbitrarily sized. You can specify the...
Read more >
decimal — Decimal fixed point and floating point arithmetic ...
The decimal module provides support for fast correctly rounded decimal floating point arithmetic. It offers several advantages over the float datatype:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found