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