import type { Node } from 'web-tree-sitter'; import type { CommaNode } from './comma.js'; import type { NameNode } from './name.js'; import type { ValueNode } from './value.js'; const TYPE = 'object_field' as const; // ================================================================ // ================================================================ // // ObjectFieldNode // // GraphQL object field node // // ================================================================ // ================================================================ /** * Represents a object field in the GraphQL AST. * * Children: * {@link CommaNode}, {@link NameNode}, {@link ValueNode} * */ export interface ObjectFieldNode extends Node { type: typeof TYPE; } // ================================================================ // ================================================================ // // Type Guard // // ================================================================ // ================================================================ /** * Type guard to check if a node is a {@link ObjectFieldNode}. * * @param node - The node to check * @returns True if the node is a {@link ObjectFieldNode} * * @example * ```typescript * if (isObjectFieldNode(node)) { * // TypeScript now knows node is ObjectFieldNode * console.log(node.type); // 'object_field' * } * ``` */ export function isObjectFieldNode(node: unknown): node is ObjectFieldNode { return (node as any)?.type === TYPE; } // ================================================================ // ================================================================ // // Constructor // // ================================================================ // ================================================================ /** * Creates a new {@link ObjectFieldNode} with the specified properties. * * @param props - The node properties * @param props.comma - {@link CommaNode} * @param props.name - {@link NameNode} * @param props.value - {@link ValueNode} * @returns A new {@link ObjectFieldNode} * * @example * ```typescript * const node = ObjectFieldNode({ * // properties... * }); * ``` */ export function ObjectFieldNode(props: Omit): ObjectFieldNode { return { type: TYPE, ...props }; }