How to use the tartiflette.types.non_null.GraphQLNonNull 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 / resolver / test_factory__resolver_executor.py View on Github external
def test_resolver_factory__resolver_executor_update_prop_contains_not_null(
    _resolver_executor_mock
):
    from tartiflette.types.field import GraphQLField
    from tartiflette.types.non_null import GraphQLNonNull
    from tartiflette.types.list import GraphQLList

    _resolver_executor_mock._schema_field = GraphQLField("A", gql_type="F")

    assert not _resolver_executor_mock.contains_not_null
    _resolver_executor_mock._schema_field = GraphQLField(
        "A", gql_type=GraphQLNonNull(gql_type="F")
    )
    assert _resolver_executor_mock.contains_not_null

    _resolver_executor_mock._schema_field = GraphQLField(
        "A", gql_type=GraphQLList(gql_type=GraphQLNonNull(gql_type="F"))
    )
    assert _resolver_executor_mock.contains_not_null

    _resolver_executor_mock._schema_field = GraphQLField(
        "A", gql_type=GraphQLList(gql_type="F")
    )
    assert not _resolver_executor_mock.contains_not_null
github tartiflette / tartiflette / tests / unit / types / test_non_null.py View on Github external
def test_graphql_non_null_eq():
    non_null = GraphQLNonNull(gql_type="Name", description="description")

    ## Same
    assert non_null == non_null
    assert non_null == GraphQLNonNull(
        gql_type="Name", description="description"
    )
    # Currently we ignore the description in comparing
    assert non_null == GraphQLNonNull(gql_type="Name")

    ## Different
    assert non_null != GraphQLNonNull(gql_type="OtherName")
github tartiflette / tartiflette / tests / unit / types / test_non_null.py View on Github external
def test_graphql_non_null_repr():
    non_null = GraphQLNonNull(gql_type="Name", description="description")

    assert (
        non_null.__repr__() == "GraphQLNonNull(gql_type='Name', "
        "description='description')"
    )
    assert non_null == eval(repr(non_null))
github tartiflette / tartiflette / tests / unit / utils / test_coercer.py View on Github external
from tartiflette.utils.coercer import _get_type_coercers
    from tartiflette.types.list import GraphQLList
    from tartiflette.types.non_null import GraphQLNonNull
    from tartiflette.utils.coercer import _list_coercer, _not_null_coercer

    assert _get_type_coercers("aType") == []
    assert _get_type_coercers(None) == []
    assert _get_type_coercers(GraphQLList(gql_type="aType")) == [_list_coercer]
    assert _get_type_coercers(GraphQLNonNull(gql_type="aType")) == [
        _not_null_coercer
    ]
    assert _get_type_coercers(
        GraphQLList(gql_type=GraphQLNonNull(gql_type="aType"))
    ) == [_list_coercer, _not_null_coercer]
    assert _get_type_coercers(
        GraphQLNonNull(
            gql_type=GraphQLList(gql_type=GraphQLNonNull(gql_type="aType"))
        )
    ) == [_not_null_coercer, _list_coercer, _not_null_coercer]
github tartiflette / tartiflette / tests / unit / types / helpers / test_reduce_type.py View on Github external
            GraphQLNonNull(
                gql_type=GraphQLList(
                    gql_type=GraphQLNonNull(gql_type="LeafType")
                )
            ),
            "LeafType",
        ),
    ],
)
def test_reduce_type(gql_type, expected):
    reduced_gql_type = reduce_type(gql_type)
    assert reduced_gql_type == expected
github tartiflette / tartiflette / tartiflette / schema / schema.py View on Github external
def _inject_introspection_fields(self) -> None:
        """
        Injects introspection fields to the query type and to defined object
        and union types.
        """
        query_type = self.type_definitions.get(self.query_operation_name)
        if not query_type:
            return

        query_type.add_field(
            SCHEMA_ROOT_FIELD_DEFINITION(
                gql_type=GraphQLNonNull("__Schema", schema=self)
            )
        )
        query_type.add_field(prepare_type_root_field(self))

        for type_definition in self.type_definitions.values():
            try:
                type_definition.add_field(
                    TYPENAME_ROOT_FIELD_DEFINITION(
                        gql_type=GraphQLNonNull(gql_type="String", schema=self)
                    )
                )
            except AttributeError:
                pass
github tartiflette / tartiflette / tartiflette / types / helpers / reduce_type.py View on Github external
def reduce_type(
    gql_type: Union[str, "GraphQLList", "GraphQLNonNull"]
) -> Union[str, "GraphQLType"]:
    """
    Unwraps the GraphQL type and to return the inner type.
    :param gql_type: schema type to unwrap
    :type gql_type: Union[str, GraphQLList, GraphQLNonNull]
    :return: the unwrapped inner schema type
    :rtype: Union[str, GraphQLType]
    """
    while isinstance(gql_type, (GraphQLList, GraphQLNonNull)):
        gql_type = gql_type.gql_type
    return gql_type
github tartiflette / tartiflette / tartiflette / sdl / transformers / schema_transformer.py View on Github external
def non_null_type(self, tree: Tree) -> SchemaNode:
        return SchemaNode(
            "non_null_type",
            GraphQLNonNull(
                gql_type=tree.children[0].value, schema=self._schema
            ),