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