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