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