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