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