import type { Node } from 'web-tree-sitter'; import type { DefaultValueNode } from './default_value.js'; import type { DescriptionNode } from './description.js'; import type { DirectivesNode } from './directives.js'; import type { NameNode } from './name.js'; import type { TypeNode } from './type.js'; const TYPE = 'input_value_definition' as const; // ================================================================ // ================================================================ // // InputValueDefinitionNode // // GraphQL input value definition node // // ================================================================ // ================================================================ /** * Represents a input value definition in the GraphQL AST. * * Children: * {@link DefaultValueNode}, {@link DescriptionNode}, {@link DirectivesNode}, {@link NameNode}, {@link TypeNode} * */ export interface InputValueDefinitionNode extends Node { type: typeof TYPE; } // ================================================================ // ================================================================ // // Type Guard // // ================================================================ // ================================================================ /** * Type guard to check if a node is a {@link InputValueDefinitionNode}. * * @param node - The node to check * @returns True if the node is a {@link InputValueDefinitionNode} * * @example * ```typescript * if (isInputValueDefinitionNode(node)) { * // TypeScript now knows node is InputValueDefinitionNode * console.log(node.type); // 'input_value_definition' * } * ``` */ export function isInputValueDefinitionNode(node: unknown): node is InputValueDefinitionNode { return (node as any)?.type === TYPE; } // ================================================================ // ================================================================ // // Constructor // // ================================================================ // ================================================================ /** * Creates a new {@link InputValueDefinitionNode} with the specified properties. * * @param props - The node properties * @param props.defaultvalue - {@link DefaultValueNode} * @param props.description - {@link DescriptionNode} * @param props.directives - {@link DirectivesNode} * @param props.name - {@link NameNode} * @param props.type - {@link TypeNode} * @returns A new {@link InputValueDefinitionNode} * * @example * ```typescript * const node = InputValueDefinitionNode({ * // properties... * }); * ``` */ export function InputValueDefinitionNode(props: Omit): InputValueDefinitionNode { return { type: TYPE, ...props }; }