import type { Node } from 'web-tree-sitter'; 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_extension' as const; // ================================================================ // ================================================================ // // InputObjectTypeExtensionNode // // GraphQL input object type extension node // // ================================================================ // ================================================================ /** * Represents a input object type extension in the GraphQL AST. * * Children: * {@link DirectivesNode}, {@link InputFieldsDefinitionNode}, {@link NameNode} * */ export interface InputObjectTypeExtensionNode extends Node { type: typeof TYPE; } // ================================================================ // ================================================================ // // Type Guard // // ================================================================ // ================================================================ /** * Type guard to check if a node is a {@link InputObjectTypeExtensionNode}. * * @param node - The node to check * @returns True if the node is a {@link InputObjectTypeExtensionNode} * * @example * ```typescript * if (isInputObjectTypeExtensionNode(node)) { * // TypeScript now knows node is InputObjectTypeExtensionNode * console.log(node.type); // 'input_object_type_extension' * } * ``` */ export function isInputObjectTypeExtensionNode(node: unknown): node is InputObjectTypeExtensionNode { return (node as any)?.type === TYPE; } // ================================================================ // ================================================================ // // Constructor // // ================================================================ // ================================================================ /** * Creates a new {@link InputObjectTypeExtensionNode} with the specified properties. * * @param props - The node properties * @param props.directives - {@link DirectivesNode} * @param props.inputfieldsdefinition - {@link InputFieldsDefinitionNode} * @param props.name - {@link NameNode} * @returns A new {@link InputObjectTypeExtensionNode} * * @example * ```typescript * const node = InputObjectTypeExtensionNode({ * // properties... * }); * ``` */ export function InputObjectTypeExtensionNode(props: Omit): InputObjectTypeExtensionNode { return { type: TYPE, ...props }; }