import type { Node } from 'web-tree-sitter'; import type { NameNode } from './name.js'; import type { ValueNode } from './value.js'; const TYPE = 'argument' as const; // ================================================================ // ================================================================ // // ArgumentNode // // GraphQL argument node // // ================================================================ // ================================================================ /** * Represents a argument in the GraphQL AST. * * Children: * {@link NameNode}, {@link ValueNode} * * @example * ```graphql * field(id: "123") # id: "123" is an ArgumentNode * ``` */ export interface ArgumentNode extends Node { type: typeof TYPE; } // ================================================================ // ================================================================ // // Type Guard // // ================================================================ // ================================================================ /** * Type guard to check if a node is a {@link ArgumentNode}. * * @param node - The node to check * @returns True if the node is a {@link ArgumentNode} * * @example * ```typescript * if (isArgumentNode(node)) { * // TypeScript now knows node is ArgumentNode * console.log(node.type); // 'argument' * } * ``` */ export function isArgumentNode(node: unknown): node is ArgumentNode { return (node as any)?.type === TYPE; } // ================================================================ // ================================================================ // // Constructor // // ================================================================ // ================================================================ /** * Creates a new {@link ArgumentNode} with the specified properties. * * @param props - The node properties * @param props.name - {@link NameNode} * @param props.value - {@link ValueNode} * @returns A new {@link ArgumentNode} * * @example * ```typescript * const node = ArgumentNode({ * // properties... * }); * ``` */ export function ArgumentNode(props: Omit): ArgumentNode { return { type: TYPE, ...props }; }