Example #1
0
def lark_to_list_type_node(tree: "Tree") -> "ListTypeNode":
    """
    Creates and returns a ListTypeNode instance extracted from the parsing of
    the tree instance.
    :param tree: the Tree to parse in order to extract the proper node
    :type tree: Tree
    :return: a ListTypeNode instance extracted from the parsing of the tree
    :rtype: ListTypeNode
    """
    return ListTypeNode(type=tree.children[0].value,
                        location=lark_to_location_node(tree.meta))
Example #2
0
def _parse_type(
    type_ast: dict
) -> Union["ListTypeNode", "NonNullTypeNode", "NamedTypeNode"]:
    """
    Creates and returns a TypeNode from a type's JSON AST libgraphqlparser
    representation.
    :param type_ast: type's JSON AST libgraphqlparser representation
    :type type_ast: dict
    :return: a TypeNode instance equivalent to the JSON AST representation
    :rtype: Union[ListTypeNode, NonNullTypeNode, NamedTypeNode]
    """
    if type_ast["kind"] == "ListType":
        return ListTypeNode(
            type=_parse_type(type_ast["type"]),
            location=_parse_location(type_ast["loc"]),
        )
    if type_ast["kind"] == "NonNullType":
        return NonNullTypeNode(
            type=_parse_type(type_ast["type"]),
            location=_parse_location(type_ast["loc"]),
        )
    return _parse_named_type(type_ast)
Example #3
0
def test_listtypenode__init__():
    list_type_node = ListTypeNode(type="listTypeType",
                                  location="listTypeLocation")
    assert list_type_node.type == "listTypeType"
    assert list_type_node.location == "listTypeLocation"
Example #4
0
from tartiflette.language.ast import ListTypeNode, NonNullTypeNode


def test_listtypenode__init__():
    list_type_node = ListTypeNode(type="listTypeType",
                                  location="listTypeLocation")
    assert list_type_node.type == "listTypeType"
    assert list_type_node.location == "listTypeLocation"


@pytest.mark.parametrize(
    "list_type_node,other,expected",
    [
        (
            ListTypeNode(type="listTypeType", location="listTypeLocation"),
            Ellipsis,
            False,
        ),
        (
            ListTypeNode(type="listTypeType", location="listTypeLocation"),
            ListTypeNode(type="listTypeTypeBis", location="listTypeLocation"),
            False,
        ),
        (
            ListTypeNode(type="listTypeType", location="listTypeLocation"),
            ListTypeNode(type="listTypeType", location="listTypeLocationBis"),
            False,
        ),
        (
            ListTypeNode(type="listTypeType", location="listTypeLocation"),