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