def test_argumentnode__init__(): argument_node = ArgumentNode(name="argumentName", value="argumentValue", location="argumentLocation") assert argument_node.name == "argumentName" assert argument_node.value == "argumentValue" assert argument_node.location == "argumentLocation"
def _parse_argument( argument_ast: dict, validators: Validators, path: Path ) -> "ArgumentNode": """ Creates and returns an ArgumentNode instance from an argument's JSON AST libgraphqlparser representation. :param argument_ast: argument's JSON AST libgraphqlparser representation :type argument_ast: dict :param validators: the validators to use in order to validate this definition :type validators: Validators :param path: a Path object that contains the current field path :type path: Path :return: an ArgumentNode instance equivalent to the JSON AST representation :rtype: ArgumentNode """ arg = ArgumentNode( name=_parse_name(argument_ast["name"]), value=_parse_value(argument_ast["value"], validators, path), location=_parse_location(argument_ast["loc"]), ) if isinstance(arg.value, VariableNode): loca = ( validators.ctx["current_directive_name"] if validators.ctx.get("in_directive", False) else validators.ctx["current_field_name"] ) if validators.ctx["in_operation"]: validators.ctx["per_operation"][ validators.ctx["current_operation_name"] ].setdefault("args_using_var", []).append( { "arg": arg, "node_location": loca, "is_directive": validators.ctx.get("in_directive", False), "path": path, } ) else: validators.ctx["per_fragment"][ validators.ctx["current_fragment_name"] ].setdefault("args_using_var", []).append( { "arg": arg, "node_location": loca, "is_directive": validators.ctx.get("in_directive", False), "path": path, } ) return arg
def _parse_argument(argument_ast: dict) -> "ArgumentNode": """ Creates and returns an ArgumentNode instance from an argument's JSON AST libgraphqlparser representation. :param argument_ast: argument's JSON AST libgraphqlparser representation :type argument_ast: dict :return: an ArgumentNode instance equivalent to the JSON AST representation :rtype: ArgumentNode """ return ArgumentNode( name=_parse_name(argument_ast["name"]), value=_parse_value(argument_ast["value"]), location=_parse_location(argument_ast["loc"]), )
def lark_to_argument_node(tree: "Tree") -> "ArgumentNode": """ Creates and returns an ArgumentNode 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: an ArgumentNode instance extracted from the parsing of the tree :rtype: ArgumentNode """ node_info = _extract_node_info(tree.children, types_to_value=["name", "value"]) return ArgumentNode( name=node_info["name"], value=node_info["value"], location=lark_to_location_node(tree.meta), )
def test_argumentnode__init__(): argument_node = ArgumentNode(name="argumentName", value="argumentValue", location="argumentLocation") assert argument_node.name == "argumentName" assert argument_node.value == "argumentValue" assert argument_node.location == "argumentLocation" @pytest.mark.parametrize( "argument_node,other,expected", [ ( ArgumentNode( name="argumentName", value="argumentValue", location="argumentLocation", ), Ellipsis, False, ), ( ArgumentNode( name="argumentName", value="argumentValue", location="argumentLocation", ), ArgumentNode( name="argumentNameBis", value="argumentValue", location="argumentLocation",