Package: tartiflette-plugin-scalars
tartiflette-plugin-scalarsTartiflette plugin providing common scalars, for data validation and strongly typed API schemas.RequirementsPython >= 3.6
Tartiflette >= 1.0.0InstallationSimply install it with pip:pip install tartiflette-plugin-scalarsThen start coding, by importing adding it to the modules list of tartiflette's create engine:importasyncioimportdatetimefromtartifletteimportResolver,create_engineasyncdefmain():sdl="""type Query {dateTime: DateTime}"""@Resolver("Query.dateTime",schema_name="scalars")asyncdefresolve_date_time(*_args,**_kwargs):returndatetime.datetime(2019,10,29,20,23,00,00)engine=awaitcreate_engine(sdl=sdl,modules=[{"name":"tartiflette_plugin_scalars","config":{"datetime":{"enabled":True}}}],schema_name="scalars",)print(awaitengine.execute("query date { dateTime }"))asyncio.run(main())ConfigurationYou can configure the plugin by passing a configuration dict during create_engine.
This configuration can be used to disable or rename some scalars, as shown below:engine = await create_engine(
    sdl=sdl,
    modules=[
        {
            "name": "tartiflette_plugin_scalars",
            "config": {
                "datetime": {"name": "MyDatetime"},
                "postal_code": {"enabled": False},
            },
        }
    ],
    schema_name="scalars",
)Some plugins also accept more specific configuration values, that can be
specified in a sub-dict calledoptions. The options will be
passed to the scalar at instanciation time as**kwargsto theinit()method.engine = await create_engine(
    sdl=sdl,
    modules=[
        {
            "name": "tartiflette_plugin_scalars",
            "config": {
                "datetime": {"name": "MyDatetime"},
                "postal_code": {"enabled": False, "options": {"key": "value"}},
            },
        }
    ],
    schema_name="scalars",
)Implemented scalars:NameConfiguration keyDescriptionEmailAddressemail_addressRepresents an email addressesDateTimedatetimeRepresents a non naive datetime objectNaiveDateTimenaive_datetimeRepresents an optionally naive datetime objectDurationdurationRepresents a timedelta objectNegativeFloatnegative_floatRepresents a negative floating point numberNegativeIntnegative_intRepresents a negative integerNonNegativeFloatnon_negative_floatRepresents a positive or 0 floating point numberNonNegativeIntnon_negative_intRepresents a positive or 0 integerPositiveFloatpositive_floatRepresents a positive floating point numberPositiveIntpositive_intRepresents a positive integerNonPositiveFloatnon_positive_floatRepresents a negative or 0 floating point numberNonPositiveIntnon_positive_intRepresents a negative or 0 integerLonglongRepresents integers between 0 and 2^63BigIntbig_intRepresents arbitrary length integersUnsignedIntunsigned_intRepresents integers between 0 and 2^32PhoneNumberphone_numberRepresents a phone numberPostalCodepostal_codeRepresents a postal codeURLurlRepresents an Uniform Resource LocatorGUIDguidRepresents a Globally Unique IDentifierUUIDuuidRepresents a Universally Unique IDentifierHexColorCodehex_color_codeHexadecimal representation of a colorHSLhslHue, Saturation and Lightness of a colorHSLAhslaHue, Saturation, Lightness and Alpha of a colorRGBrgbRed, Green, Blue of a colorRGBArgbaRed, Green, Blue and Alpha of a colorIPv4ipv4Represents an Internet Protocol version 4 addressIPv6ipv6Represents an Internet Protocol version 6 addressMACmacRepresents a Media Access Control addressISBNisbnRepresents an International Standard Book NumberPortportRepresents a TCP / UDP portUSCurrencyus_currencyRepresents an amount of USDJSONjsonRepresents a JSON valueJSONObjectjson_objectRepresents a JSON objectGeoJSONgeo_jsonRepresents a GeoJSON value