예제 #1
0
async def bake(schema_name, config):
    sdl = get_sdl(config['sdl'])
    Scalar("_Any")(Json)
    Scalar("_FieldSet")(AnyScalar)

    @Resolver('Query._service')
    async def revolve_service(_, args, ctx, info):
        return {
            'sdl': sdl + BUILTINS,
        }

    return _SDL
예제 #2
0
def bake(schema_name: str, config: Optional[Dict[str, Any]] = None) -> str:
    """
    Links the scalar to the appropriate schema and returns the SDL related
    to the scalar.
    :param schema_name: schema name to link with
    :param config: configuration of the scalar
    :type schema_name: str
    :type config: Optional[Dict[str, Any]]
    :return: the SDL related to the scalar
    :rtype: str
    """
    # pylint: disable=unused-argument
    Scalar("Boolean", schema_name=schema_name)(ScalarBoolean())
    return '''
예제 #3
0
def _generate_scalars(schema_name, config):
    scalars = []

    for scalar in AVAILABLE_SCALARS:
        scalar_config = config.get(scalar[0], {})
        if scalar_config.get("enabled") is not False:
            scalar_mod = import_module(
                f"tartiflette_plugin_scalars.{scalar[0]}"
            )
            scalar_class = getattr(scalar_mod, scalar[1])

            scalar_name = scalar_config.get("name") or scalar[1]
            Scalar(name=scalar_name, schema_name=schema_name)(
                scalar_class(**scalar_config.get("options", {}))
            )
            scalars.append(_SCALAR_TEMPLATE.format(scalar_name))

    return scalars
예제 #4
0
def bake(schema_name, config):
    Scalar("DefaultRawInt", schema_name="coercion")(IntScalar())
    Scalar("DefaultRawString", schema_name="coercion")(StringScalar())
    Scalar("Boolean", schema_name="coercion")(BooleanScalar())
    Scalar("Float", schema_name="coercion")(FloatScalar())
    Scalar("Int", schema_name="coercion")(IntScalar())
    Scalar("String", schema_name="coercion")(StringScalar())
    Directive("debug", schema_name="coercion")(DebugDirective())
    Directive("lowercase", schema_name="coercion")(LowercaseDirective())
    Directive("increment", schema_name="coercion")(IncrementDirective())
    Directive("concatenate", schema_name="coercion")(ConcatenateDirective())
    Directive("mapToValue", schema_name="coercion")(MapToValueDirective())
    return ""
예제 #5
0
async def bake(schema_name, config):
    Directive("Blah", schema_name=schema_name)(BlahDir(config))
    Scalar("NinjaGo", schema_name=schema_name)(NinjaGo)
    Resolver("Lol.ninja", schema_name=schema_name)(resolver_of_lol_ninja)
    return _SDL
예제 #6
0
def bake(schema_name, _config):
    sdl = "scalar Date"

    Scalar("Date", schema_name=schema_name)(ScalarDate())

    return sdl
예제 #7
0
from tartiflette import Scalar
from typing import Union
from tartiflette.language.ast.base import Node
from tartiflette.constants import UNDEFINED_VALUE
from tartiflette_scalars import Json, ObjectId, AnyScalar


JsonScalar = Scalar("Json")
JsonScalar(Json)

AnyScalarScalar = Scalar("AnyScalar")
AnyScalarScalar(AnyScalar)

ObjectIdScalar = Scalar("ObjectId")
ObjectIdScalar(ObjectId)



UrlScalar = Scalar("Url")
@UrlScalar
class UrlClass:
    @staticmethod
    def coerce_input(val):
        return val

    @staticmethod
    def coerce_output(val):
        return val

    def parse_literal(self, ast: "Node") -> Union[str, "UNDEFINED_VALUE"]:
예제 #8
0
def bake(schema_name, _config):
    sdl = "scalar Time"

    Scalar("Time", schema_name=schema_name)(ScalarTime())

    return sdl
예제 #9
0
def bake(schema_name, _config):
    sdl = "scalar Boolean"

    Scalar(name="Boolean", schema_name=schema_name)(ScalarBoolean())

    return sdl
예제 #10
0
        "a",
    )
    clean_registry.register_sdl("a", full_sdl)
    schema = SchemaBakery.bake("a")
    assert schema.has_type(type_name) is expected


@pytest.mark.parametrize(
    "schema_name,where,obj",
    [
        (
            "directives_schema",
            "directives",
            Directive("my_directive", "directives_schema"),
        ),
        ("scalars_schema", "scalars", Scalar("my_scalar", "scalars_schema")),
        (
            "resolvers_schema",
            "resolvers",
            Resolver("my_resolver", "resolvers_schema"),
        ),
    ],
)
def test_schema_registry_register(clean_registry, schema_name, where, obj):
    SchemaRegistry._register(schema_name, where, obj)

    with pytest.raises(ImproperlyConfigured) as excinfo:
        SchemaRegistry._register(schema_name, where, obj)

    assert str(excinfo.value) == (
        "Can't register < %s > to < %s > %s because it's already registered" %
예제 #11
0
def bake(schema_name, _config):
    sdl = "scalar Int"

    Scalar(name="Int", schema_name=schema_name)(ScalarInt())

    return sdl
예제 #12
0
def bake(schema_name, _config):
    sdl = "scalar String"

    Scalar(name="String", schema_name=schema_name)(ScalarString())

    return sdl
예제 #13
0
from tartiflette import Scalar
from tartiflette_scalars import Json, ObjectId

JsonScalar = Scalar("Json")(Json)