How to use the tartiflette.types.type.GraphQLType 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 / tartiflette / types / object.py View on Github external
)
from tartiflette.coercers.outputs.object_coercer import object_coercer
from tartiflette.types.helpers.get_directive_instances import (
    compute_directive_nodes,
)
from tartiflette.types.type import (
    GraphQLCompositeType,
    GraphQLExtension,
    GraphQLType,
)
from tartiflette.utils.directives import wraps_with_directives

__all__ = ("GraphQLObjectType",)


class GraphQLObjectType(GraphQLCompositeType, GraphQLType):
    """
    Definition of a GraphQL object.
    """

    # Introspection attributes
    kind = "OBJECT"

    def __init__(
        self,
        name: str,
        fields: Dict[str, "GraphQLField"],
        interfaces: Optional[List[str]] = None,
        description: Optional[str] = None,
        directives: Optional[List["DirectiveNode"]] = None,
    ) -> None:
        """
github tartiflette / tartiflette / tartiflette / types / type.py View on Github external
def wrapped_type(self) -> "GraphQLType":
        """
        Returns the wrapped GraphQL type of the wrapping type.
        :return: the wrapped GraphQL type of the wrapping type
        :rtype: GraphQLType
        """
        return (
            self.gql_type
            if isinstance(self.gql_type, GraphQLType)
            else self._schema.find_type(self.gql_type)
        )
github tartiflette / tartiflette / tartiflette / types / object.py View on Github external
:type custom_default_resolver: Optional[Callable]
        """
        if self.implemented_fields:
            for field in self.implemented_fields.values():
                field.bake(schema, custom_default_resolver)
                field = await field.on_post_bake()

                if not field.name.startswith("__"):
                    self.fields.append(field)

    @property
    def possible_types_set(self) -> set:
        return self._possible_types_set


class GraphQLObjectTypeExtension(GraphQLType, GraphQLExtension):
    def __init__(self, name, fields, directives, interfaces):
        self.name = name
        self.fields = fields or {}
        self.directives = directives
        self.interfaces = interfaces or []

    def bake(self, schema):
        extended = schema.find_type(self.name)
        extended.directives.extend(self.directives)
        extended.implemented_fields.update(self.fields)
        extended.interfaces_names.extend(self.interfaces)

    def __eq__(self, other: Any) -> bool:
        """
        Returns True if `other` instance is identical to `self`.
        :param other: object instance to compare to `self`
github tartiflette / tartiflette / tartiflette / types / argument.py View on Github external
def bake(self, schema: "GraphQLSchema") -> None:
        """
        Bakes the GraphQLArgument and computes all the necessary stuff for
        execution.
        :param schema: the GraphQLSchema instance linked to the engine
        :type schema: GraphQLSchema
        """
        self.graphql_type = get_graphql_type(schema, self.gql_type)

        if isinstance(self.gql_type, GraphQLType):
            self.type = self.gql_type
        else:
            self.type["name"] = self.gql_type
            self.type["kind"] = self.graphql_type.kind

        # Directives
        directives_definition = compute_directive_nodes(
            schema, self.directives
        )
        self.introspection_directives = wraps_with_directives(
            directives_definition=directives_definition,
            directive_hook="on_introspection",
        )

        # Coercers
        self.literal_coercer = get_literal_coercer(self.graphql_type)
github tartiflette / tartiflette / tartiflette / types / scalar.py View on Github external
)
from tartiflette.coercers.outputs.scalar_coercer import scalar_coercer
from tartiflette.types.helpers.get_directive_instances import (
    compute_directive_nodes,
)
from tartiflette.types.type import (
    GraphQLExtension,
    GraphQLInputType,
    GraphQLType,
)
from tartiflette.utils.directives import wraps_with_directives

__all__ = ("GraphQLScalarType",)


class GraphQLScalarType(GraphQLInputType, GraphQLType):
    """
    Definition of a GraphQL scalar.
    """

    # Introspection attributes
    kind = "SCALAR"

    def __init__(
        self,
        name: str,
        description: Optional[str] = None,
        directives: Optional[List["DirectiveNode"]] = None,
    ) -> None:
        """
        :param name: name of the scalar
        :param description: description of the scalar
github tartiflette / tartiflette / tartiflette / types / input_object.py View on Github external
input_object_coercer as literal_input_object_coercer,
)
from tartiflette.types.helpers.get_directive_instances import (
    compute_directive_nodes,
)
from tartiflette.types.type import (
    GraphQLExtension,
    GraphQLInputType,
    GraphQLType,
)
from tartiflette.utils.directives import wraps_with_directives

__all__ = ("GraphQLInputObjectType",)


class GraphQLInputObjectType(GraphQLInputType, GraphQLType):
    """
    Definition of a GraphQL input object.
    """

    # Introspection attributes
    kind = "INPUT_OBJECT"

    def __init__(
        self,
        name: str,
        fields: Dict[str, "GraphQLInputField"],
        description: Optional[str] = None,
        directives: Optional[List["DirectiveNode"]] = None,
    ) -> None:
        """
        :param name: name of the input object
github tartiflette / tartiflette / tartiflette / types / type.py View on Github external
:type other: Any
        :return: whether or not `other` is identical to `self`
        :rtype: bool
        """
        return self is other or type(self) is type(other)

    def __repr__(self) -> str:
        """
        Returns the representation of a GraphQLType instance.
        :return: the representation of a GraphQLType instance
        :rtype: str
        """
        return "{}()".format(self.__class__.__name__)


class GraphQLWrappingType(GraphQLType):
    """
    Definition of a GraphQL wrapping type.
    """

    is_wrapping_type = True

    def __init__(
        self,
        gql_type: Union["GraphQLList", str],
        schema: Optional["GraphQLSchema"] = None,
    ) -> None:
        """
        :param gql_type: inner GraphQL type of the wrapping type
        :param schema: the GraphQLSchema instance linked to the type
        :type gql_type: Union[GraphQLList, str]
        :type schema: Optional[GraphQLSchema]
github tartiflette / tartiflette / tartiflette / types / interface.py View on Github external
:param schema: the GraphQLSchema instance linked to the engine
        :param custom_default_resolver: callable that will replace the builtin
        default_resolver
        :type schema: GraphQLSchema
        :type custom_default_resolver: Optional[Callable]
        """
        if self.implemented_fields:
            for field in self.implemented_fields.values():
                field.bake(schema, custom_default_resolver)
                field = await field.on_post_bake()

                if not field.name.startswith("__"):
                    self.fields.append(field)


class GraphQLInterfaceTypeExtension(GraphQLType, GraphQLExtension):
    def __init__(self, name, directives, fields):
        self.name = name
        self.directives = directives
        self.fields = fields or []

    def bake(self, schema):
        extended = schema.find_type(self.name)

        extended.directives.extend(self.directives)
        extended.implemented_fields.update(self.fields)

    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
github tartiflette / tartiflette / tartiflette / types / input_field.py View on Github external
def bake(self, schema: "GraphQLSchema") -> None:
        """
        Bakes the GraphQLInputField and computes all the necessary stuff for
        execution.
        :param schema: the GraphQLSchema instance linked to the engine
        :type schema: GraphQLSchema
        """
        self.graphql_type = get_graphql_type(schema, self.gql_type)

        if isinstance(self.gql_type, GraphQLType):
            self.type = self.gql_type
        else:
            self.type["name"] = self.gql_type
            self.type["kind"] = self.graphql_type.kind

        self.defaultValue = (
            str(self.default_value) if self.default_value is not None else None
        )

        # Directives
        directives_definition = compute_directive_nodes(
            schema, self.directives
        )
        self.introspection_directives = wraps_with_directives(
            directives_definition=directives_definition,
            directive_hook="on_introspection",
github tartiflette / tartiflette / tartiflette / types / enum.py View on Github external
),
        )

    async def bake_enum_values(self, schema: "GraphQLSchema") -> None:
        """
        Bakes enum's values.
        :param schema: the GraphQLSchema instance linked to the engine
        :type schema: GraphQLSchema
        """
        for enum_value in self.values:
            enum_value.bake(schema)
            enum_value = await enum_value.on_post_bake()
            self._value_map[enum_value.name] = enum_value


class GraphQLEnumTypeExtension(GraphQLType, GraphQLExtension):
    def __init__(self, name, directives, values):
        self.name = name
        self.directives = directives
        self.values = values or []

    def bake(self, schema):
        enum = schema.find_type(self.name)
        enum.directives.extend(self.directives)
        enum.values.extend(self.values)

    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`