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