How to use the sgqlc.types.Scalar function in sgqlc

To help you get started, we’ve selected a few sgqlc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chaoss / grimoirelab-sortinghat / sortinghat / cli / client / schema.py View on Github external
import sgqlc.types
import sgqlc.types.datetime


sh_schema = sgqlc.types.Schema()


########################################################################
# Scalars and Enumerations
########################################################################
Boolean = sgqlc.types.Boolean

DateTime = sgqlc.types.datetime.DateTime


class GenericScalar(sgqlc.types.Scalar):
    __schema__ = sh_schema


ID = sgqlc.types.ID

Int = sgqlc.types.Int


class OperationArgsType(sgqlc.types.Scalar):
    __schema__ = sh_schema


class OperationOpType(sgqlc.types.Enum):
    __schema__ = sh_schema
    __choices__ = ('ADD', 'DELETE', 'UPDATE')
github profusion / sgqlc / sgqlc / types / datetime.py View on Github external
ValueError: MyDateTimeType selection 'datetime1': ...

:license: ISC
'''

__docformat__ = 'reStructuredText en'

__all__ = ('Time', 'Date', 'DateTime')

import datetime
import re

from . import Scalar, map_python_to_graphql


class Time(Scalar):
    '''Time encoded as string using ISO8601 (HH:MM:SS[.mmm][+/-HH:MM])

    While not a standard GraphQL type, it's often used, so expose to
    make life simpler.

    >>> Time('12:34:56') # naive, no timezone
    datetime.time(12, 34, 56)
    >>> Time('12:34:56Z') # Z = GMT/UTC
    datetime.time(12, 34, 56, tzinfo=datetime.timezone.utc)
    >>> Time('12:34:56-05:30') # doctest: +ELLIPSIS
    datetime.time(12, 34, 56, tzinfo=...(days=-1, seconds=70200)))
    >>> Time('12:34:56+05:30') # doctest: +ELLIPSIS
    datetime.time(12, 34, 56, tzinfo=...(seconds=19800)))
    >>> Time('123456') # compact form
    datetime.time(12, 34, 56)
    >>> Time('123456Z') # compact form, GMT/UTC
github chaoss / grimoirelab-sortinghat / sortinghat / cli / client / schema.py View on Github external
########################################################################
Boolean = sgqlc.types.Boolean

DateTime = sgqlc.types.datetime.DateTime


class GenericScalar(sgqlc.types.Scalar):
    __schema__ = sh_schema


ID = sgqlc.types.ID

Int = sgqlc.types.Int


class OperationArgsType(sgqlc.types.Scalar):
    __schema__ = sh_schema


class OperationOpType(sgqlc.types.Enum):
    __schema__ = sh_schema
    __choices__ = ('ADD', 'DELETE', 'UPDATE')


String = sgqlc.types.String


########################################################################
# Input Objects
########################################################################

class CountryFilterType(sgqlc.types.Input):
github profusion / sgqlc / sgqlc / types / datetime.py View on Github external
elif m['TZ']:
            d = datetime.timedelta(hours=int(m['TZH']), minutes=int(m['TZM']))
            tzinfo = datetime.timezone(d)

        return datetime.time(hour, minute, second, microsecond, tzinfo)

    @classmethod
    def __to_json_value__(cls, value):
        if value is None:
            return None
        if isinstance(value, str):
            return value
        return value.isoformat()


class Date(Scalar):
    '''Date encoded as string using ISO8601 (YYYY-MM-SS)

    While not a standard GraphQL type, it's often used, so expose to
    make life simpler.

    >>> Date('2018-01-02')
    datetime.date(2018, 1, 2)
    >>> Date('20180102') # compact form
    datetime.date(2018, 1, 2)

    Pre-converted values are allowed:

    >>> Date(datetime.date(2018, 1, 2))
    datetime.date(2018, 1, 2)

    It can also serialize to JSON:
github profusion / sgqlc / sgqlc / types / datetime.py View on Github external
year = int(m['Y'])
        month = int(m['m'])
        day = int(m['d'])
        return datetime.date(year, month, day)

    @classmethod
    def __to_json_value__(cls, value):
        if value is None:
            return None
        if isinstance(value, str):
            return value
        return value.isoformat()


class DateTime(Scalar):
    '''Date and Time encoded as string using ISO8601
    (YYYY-mm-ddTHH:MM:SS[.mmm][+/-HH:MM])

    While not a standard GraphQL type, it's often used, so expose to
    make life simpler.

    >>> DateTime('2018-01-02T12:34:56') # naive, no timezone
    datetime.datetime(2018, 1, 2, 12, 34, 56)
    >>> DateTime('2018-01-02T12:34:56Z') # Z = GMT/UTC
    datetime.datetime(2018, 1, 2, 12, 34, 56, tzinfo=datetime.timezone.utc)
    >>> DateTime('2018-01-02T12:34:56-05:30') # doctest: +ELLIPSIS
    datetime.datetime(2018, 1, 2, 12, 34, 56, tzinfo=..., seconds=70200)))
    >>> DateTime('2018-01-02T12:34:56+05:30') # doctest: +ELLIPSIS
    datetime.datetime(2018, 1, 2, 12, 34, 56, tzinfo=...(seconds=19800)))
    >>> DateTime('20180102T123456') # compact form
    datetime.datetime(2018, 1, 2, 12, 34, 56)