def test_directivenode__init__():
    directive_node = DirectiveNode(
        name="directiveName",
        arguments="directiveArguments",
        location="directiveLocation",
    )
    assert directive_node.name == "directiveName"
    assert directive_node.arguments == "directiveArguments"
    assert directive_node.location == "directiveLocation"
Exemple #2
0
def _parse_directive(directive_ast: dict) -> "DirectiveNode":
    """
    Creates and returns a DirectiveNode instance from a directive's JSON AST
    libgraphqlparser representation.
    :param directive_ast: directive's JSON AST libgraphqlparser representation
    :type directive_ast: dict
    :return: a DirectiveNode instance equivalent to the JSON AST representation
    :rtype: DirectiveNode
    """
    return DirectiveNode(
        name=_parse_name(directive_ast["name"]),
        arguments=_parse_arguments(directive_ast["arguments"]),
        location=_parse_location(directive_ast["loc"]),
    )
Exemple #3
0
def lark_to_directive_node(tree: "Tree") -> "DirectiveNode":
    """
    Creates and returns a DirectiveNode 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 DirectiveNode instance extracted from the parsing of the tree
    :rtype: DirectiveNode
    """
    node_info = _extract_node_info(tree.children,
                                   types_to_value=["name", "arguments"])

    return DirectiveNode(
        name=node_info["name"],
        arguments=node_info.get("arguments") or [],
        location=lark_to_location_node(tree.meta),
    )
Exemple #4
0
def _parse_directive(
    directive_ast: dict, validators: "Validators", path: "Path"
) -> "DirectiveNode":
    """
    Creates and returns a DirectiveNode instance from a directive's JSON AST
    libgraphqlparser representation.
    :param directive_ast: directive's JSON AST libgraphqlparser representation
    :type directive_ast: dict
    :param validators: the Validators object that will be used to validate these arguments
    :param path: a Path object that contains the current field path
    :type validators: Validators
    :type path: Path
    :return: a DirectiveNode instance equivalent to the JSON AST representation
    :rtype: DirectiveNode
    """
    name = _parse_name(directive_ast["name"])
    validators.ctx["in_directive"] = True
    validators.ctx["current_directive_name"] = name.value

    directive = DirectiveNode(
        name=name,
        arguments=_parse_arguments(
            directive_ast["arguments"], validators, path
        ),
        location=_parse_location(directive_ast["loc"]),
    )

    validators.ctx["in_directive"] = False

    validators.validate(
        rule="values-of-correct-type", node=directive, path=path
    )

    validators.validate(rule="argument-names", node=directive, path=path)

    validators.validate(rule="required-arguments", node=directive, path=path)

    validators.validate(
        rule="directives-are-defined", directive=directive, path=path
    )

    return directive
        name="directiveName",
        arguments="directiveArguments",
        location="directiveLocation",
    )
    assert directive_node.name == "directiveName"
    assert directive_node.arguments == "directiveArguments"
    assert directive_node.location == "directiveLocation"


@pytest.mark.parametrize(
    "directive_node,other,expected",
    [
        (
            DirectiveNode(
                name="directiveName",
                arguments="directiveArguments",
                location="directiveLocation",
            ),
            Ellipsis,
            False,
        ),
        (
            DirectiveNode(
                name="directiveName",
                arguments="directiveArguments",
                location="directiveLocation",
            ),
            DirectiveNode(
                name="directiveNameBis",
                arguments="directiveArguments",
                location="directiveLocation",