import type { Node } from 'web-tree-sitter'; import type { FragmentDefinitionNode } from './fragment_definition.js'; import type { OperationDefinitionNode } from './operation_definition.js'; const TYPE = 'executable_definition' as const; // ================================================================ // ================================================================ // // ExecutableDefinitionNode // // GraphQL executable definition node // // ================================================================ // ================================================================ /** * Represents a executable definition in the GraphQL AST. * * Children: * {@link FragmentDefinitionNode}, {@link OperationDefinitionNode} * */ export interface ExecutableDefinitionNode extends Node { type: typeof TYPE; } // ================================================================ // ================================================================ // // Type Guard // // ================================================================ // ================================================================ /** * Type guard to check if a node is a {@link ExecutableDefinitionNode}. * * @param node - The node to check * @returns True if the node is a {@link ExecutableDefinitionNode} * * @example * ```typescript * if (isExecutableDefinitionNode(node)) { * // TypeScript now knows node is ExecutableDefinitionNode * console.log(node.type); // 'executable_definition' * } * ``` */ export function isExecutableDefinitionNode(node: unknown): node is ExecutableDefinitionNode { return (node as any)?.type === TYPE; } // ================================================================ // ================================================================ // // Constructor // // ================================================================ // ================================================================ /** * Creates a new {@link ExecutableDefinitionNode} with the specified properties. * * @param props - The node properties * @param props.fragmentdefinition - {@link FragmentDefinitionNode} * @param props.operationdefinition - {@link OperationDefinitionNode} * @returns A new {@link ExecutableDefinitionNode} * * @example * ```typescript * const node = ExecutableDefinitionNode({ * // properties... * }); * ``` */ export function ExecutableDefinitionNode(props: Omit): ExecutableDefinitionNode { return { type: TYPE, ...props }; }