How to use the tartiflette.types.scalar.GraphQLScalarType function in tartiflette

To help you get started, we’ve selected a few tartiflette 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 tartiflette / tartiflette / tests / unit / types / test_scalar.py View on Github external
def test_graphql_scalar_init():
    scalar = GraphQLScalarType(name="Name", description="description")

    assert scalar.name == "Name"
    assert scalar.coerce_output is None
    assert scalar.coerce_input is None
    assert scalar.description == "description"
github tartiflette / tartiflette / tests / unit / types / builtins / scalars.py View on Github external
def test_scalar_id():
    var_id = GraphQLID

    assert isinstance(var_id, GraphQLScalarType)
    assert var_id.name == "ID"
github tartiflette / tartiflette / tests / unit / types / test_scalar.py View on Github external
def test_graphql_scalar_eq():
    scalar = GraphQLScalarType(name="Name", description="description")

    ## Same
    assert scalar == scalar
    assert scalar == GraphQLScalarType(name="Name", description="description")
    # Currently we ignore the description in comparing
    assert scalar == GraphQLScalarType(name="Name")

    ## Different
    assert scalar != GraphQLScalarType(name="OtherName")
github tartiflette / tartiflette / tests / unit / sdl / transformer / test_schema_transformer.py View on Github external
                            GraphQLScalarType,
                            name="Date",
                            description="\n        Date scalar for "
                            "storing Dates, "
                            "very convenient\n        ",
                        )
                    ],
                )
            ],
        ),
        (
            """
        \"\"\"
        DateOrTime scalar for storing Date or Time, very convenient also
        \"\"\"
        union DateOrTime = Date | Time
        """,
github tartiflette / tartiflette / tartiflette / types / builtins / scalars.py View on Github external
from tartiflette.types.scalar import GraphQLScalarType

GraphQLBoolean = GraphQLScalarType(
    name="Boolean", coerce_output=bool, coerce_input=bool
)

GraphQLFloat = GraphQLScalarType(
    name="Float", coerce_output=float, coerce_input=float
)

GraphQLID = GraphQLScalarType(name="ID", coerce_output=str, coerce_input=str)

GraphQLInt = GraphQLScalarType(name="Int", coerce_output=int, coerce_input=int)

GraphQLString = GraphQLScalarType(
    name="String", coerce_output=str, coerce_input=str
)
github tartiflette / tartiflette / tartiflette / schema / transformer.py View on Github external
) -> Optional["GraphQLScalarType"]:
    """
    Computes an AST scalar type definition node into a GraphQLScalarType
    instance.
    :param scalar_type_definition_node: AST scalar type definition node to
    treat
    :param schema: the GraphQLSchema instance linked to the engine
    :type scalar_type_definition_node: ScalarTypeDefinitionNode
    :type schema: GraphQLSchema
    :return: the computed GraphQLScalarType instance
    :rtype: Optional[GraphQLScalarType]
    """
    if not scalar_type_definition_node:
        return None

    scalar_type = GraphQLScalarType(
        name=parse_name(scalar_type_definition_node.name, schema),
        description=parse_name(
            scalar_type_definition_node.description, schema
        ),
        directives=scalar_type_definition_node.directives,
    )
    schema.add_scalar_definition(scalar_type)
    return scalar_type
github tartiflette / tartiflette / tartiflette / schema / schema.py View on Github external
def _validate_all_scalars_have_implementations(self) -> List[str]:
        """
        Validates that defined scalar types provide a proper implementation.
        :return: a list of errors
        :rtype: List[str]
        """
        errors = []
        for type_name, gql_type in self.type_definitions.items():
            if isinstance(gql_type, GraphQLScalarType) and (
                gql_type.coerce_output is None
                or gql_type.coerce_input is None
                or gql_type.parse_literal is None
            ):
                errors.append(
                    f"Scalar < {type_name} > " f"is missing an implementation"
                )
        return errors
github tartiflette / tartiflette / tartiflette / language / validators / query / values_of_correct_type.py View on Github external
errors = self._validate(
                    r_argument_schema_type,
                    c_argument_schema_type.gql_type,
                    arg,
                    path,
                    errors,
                    schema,
                    value_node=arg_value,
                    input_field=input_field,
                )
            return errors

        if isinstance(value_node, NullValueNode):
            return errors  # Because it's not non null, null node is okay

        if isinstance(r_argument_schema_type, GraphQLScalarType) and (
            r_argument_schema_type.parse_literal(value_node) is UNDEFINED_VALUE
        ):
            errors.append(
                graphql_error_from_nodes(
                    message=f"Value {value_node.value} is not of correct type {r_argument_schema_type.name}",
                    nodes=input_field or arg,
                    extensions=self._extensions,
                    path=path,
                )
            )
            return errors

        if isinstance(r_argument_schema_type, GraphQLInputObjectType):
            errors = self._validate_input_object(
                arg=arg,
                schema_argument_definition=r_argument_schema_type,
github tartiflette / tartiflette / tartiflette / types / builtins / scalars.py View on Github external
from tartiflette.types.scalar import GraphQLScalarType

GraphQLBoolean = GraphQLScalarType(
    name="Boolean", coerce_output=bool, coerce_input=bool
)

GraphQLFloat = GraphQLScalarType(
    name="Float", coerce_output=float, coerce_input=float
)

GraphQLID = GraphQLScalarType(name="ID", coerce_output=str, coerce_input=str)

GraphQLInt = GraphQLScalarType(name="Int", coerce_output=int, coerce_input=int)

GraphQLString = GraphQLScalarType(
    name="String", coerce_output=str, coerce_input=str
)
github tartiflette / tartiflette / tartiflette / types / scalar.py View on Github external
def __eq__(self, other: Any) -> bool:
        """
        Returns True if `other` instance is identical to `self`.
        :param other: object instance to compare to `self`
        :type other: Any
        :return: whether or not `other` is identical to `self`
        :rtype: bool
        """
        return self is other or (
            isinstance(other, GraphQLScalarType)
            and self.name == other.name
            and self.description == other.description
            and self.directives == other.directives
            and self.coerce_output == other.coerce_output
            and self.coerce_input == other.coerce_input
            and self.parse_literal == other.parse_literal
        )