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