import type { Node } from 'web-tree-sitter'; import type { ExecutableDirectiveLocationNode } from './executable_directive_location.js'; import type { TypeSystemDirectiveLocationNode } from './type_system_directive_location.js'; const TYPE = 'directive_location' as const; // ================================================================ // ================================================================ // // DirectiveLocationNode // // GraphQL directive location node // // ================================================================ // ================================================================ /** * Represents a directive location in the GraphQL AST. * * Children: * {@link ExecutableDirectiveLocationNode}, {@link TypeSystemDirectiveLocationNode} * */ export interface DirectiveLocationNode extends Node { type: typeof TYPE; } // ================================================================ // ================================================================ // // Type Guard // // ================================================================ // ================================================================ /** * Type guard to check if a node is a {@link DirectiveLocationNode}. * * @param node - The node to check * @returns True if the node is a {@link DirectiveLocationNode} * * @example * ```typescript * if (isDirectiveLocationNode(node)) { * // TypeScript now knows node is DirectiveLocationNode * console.log(node.type); // 'directive_location' * } * ``` */ export function isDirectiveLocationNode(node: unknown): node is DirectiveLocationNode { return (node as any)?.type === TYPE; } // ================================================================ // ================================================================ // // Constructor // // ================================================================ // ================================================================ /** * Creates a new {@link DirectiveLocationNode} with the specified properties. * * @param props - The node properties * @param props.executabledirectivelocation - {@link ExecutableDirectiveLocationNode} * @param props.typesystemdirectivelocation - {@link TypeSystemDirectiveLocationNode} * @returns A new {@link DirectiveLocationNode} * * @example * ```typescript * const node = DirectiveLocationNode({ * // properties... * }); * ``` */ export function DirectiveLocationNode(props: Omit): DirectiveLocationNode { return { type: TYPE, ...props }; }