Skip to main content

tartiflette-plugin-scalars

Tartiflette plugin providing common scalars, for data validation and strongly typed API schemas.

Requirements

Python >= 3.6 Tartiflette >= 1.0.0

Installation

Simply install it with pip:

pip install tartiflette-plugin-scalars

Then start coding, by importing adding it to the modules list of tartiflette's create engine:

import asyncio
import datetime

from tartiflette import Resolver, create_engine

async def main():
    sdl = """
    type Query {
      dateTime: DateTime
    }
    """

    @Resolver("Query.dateTime", schema_name="scalars")
    async def resolve_date_time(*_args, **_kwargs):
        return datetime.datetime(2019, 10, 29, 20, 23, 00, 00)

    engine = await create_engine(
        sdl=sdl,
        modules=[
            {
                "name": "tartiflette_plugin_scalars",
                "config": {"datetime": {"enabled": True}}
            }
        ],
        schema_name="scalars",
    )

    print(await engine.execute("query date { dateTime }"))


asyncio.run(main())

Configuration

You 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 called options. The options will be passed to the scalar at instanciation time as **kwargs to the init() 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:

Name Configuration key Description
EmailAddress email_address Represents an email addresses
DateTime datetime Represents a non naive datetime object
NaiveDateTime naive_datetime Represents an optionally naive datetime object
Duration duration Represents a timedelta object
NegativeFloat negative_float Represents a negative floating point number
NegativeInt negative_int Represents a negative integer
NonNegativeFloat non_negative_float Represents a positive or 0 floating point number
NonNegativeInt non_negative_int Represents a positive or 0 integer
PositiveFloat positive_float Represents a positive floating point number
PositiveInt positive_int Represents a positive integer
NonPositiveFloat non_positive_float Represents a negative or 0 floating point number
NonPositiveInt non_positive_int Represents a negative or 0 integer
Long long Represents integers between 0 and 2^63
BigInt big_int Represents arbitrary length integers
UnsignedInt unsigned_int Represents integers between 0 and 2^32
PhoneNumber phone_number Represents a phone number
PostalCode postal_code Represents a postal code
URL url Represents an Uniform Resource Locator
GUID guid Represents a Globally Unique IDentifier
UUID uuid Represents a Universally Unique IDentifier
HexColorCode hex_color_code Hexadecimal representation of a color
HSL hsl Hue, Saturation and Lightness of a color
HSLA hsla Hue, Saturation, Lightness and Alpha of a color
RGB rgb Red, Green, Blue of a color
RGBA rgba Red, Green, Blue and Alpha of a color
IPv4 ipv4 Represents an Internet Protocol version 4 address
IPv6 ipv6 Represents an Internet Protocol version 6 address
MAC mac Represents a Media Access Control address
ISBN isbn Represents an International Standard Book Number
Port port Represents a TCP / UDP port
USCurrency us_currency Represents an amount of USD
JSON json Represents a JSON value
JSONObject json_object Represents a JSON object
GeoJSON geo_json Represents a GeoJSON value

Metadata

Release files for tartiflette-plugin-scalars 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tartiflette-plugin-scalars 0.3.1
File Size Uploaded
tartiflette-plugin-scalars-0.3.1.tar.gz 14.4 kB Details

Release files / tartiflette-plugin-scalars-0.3.1.tar.gz

Download URL tartiflette-plugin-scalars-0.3.1.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a17bd0672120cb1c41c7ccdf8d70cc462f9cf37c5083bcd9ef5bbca8d58e7119
BLAKE2b-256 checksum
How to use checksums
260b6945b7dd75c09b7f6f1ffbad09a7833c11cde6218e9cfea272e2ad26191c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.7.2

Release history Release notifications | RSS feed

This release

0.3.1 This release

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page