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 = 'object_type_extension' as const; // ================================================================ // ================================================================ // // ObjectTypeExtensionNode // // GraphQL object type extension node // // ================================================================ // ================================================================ /** * Represents a object type extension in the GraphQL AST. * * Children: * {@link DirectivesNode}, {@link FieldsDefinitionNode}, {@link ImplementsInterfacesNode}, {@link NameNode} * */ export interface ObjectTypeExtensionNode extends Node { type: typeof TYPE; } // ================================================================ // ================================================================ // // Type Guard // // ================================================================ // ================================================================ /** * Type guard to check if a node is a {@link ObjectTypeExtensionNode}. * * @param node - The node to check * @returns True if the node is a {@link ObjectTypeExtensionNode} * * @example * ```typescript * if (isObjectTypeExtensionNode(node)) { * // TypeScript now knows node is ObjectTypeExtensionNode * console.log(node.type); // 'object_type_extension' * } * ``` */ export function isObjectTypeExtensionNode(node: unknown): node is ObjectTypeExtensionNode { return (node as any)?.type === TYPE; } // ================================================================ // ================================================================ // // Constructor // // ================================================================ // ================================================================ /** * Creates a new {@link ObjectTypeExtensionNode} 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 ObjectTypeExtensionNode} * * @example * ```typescript * const node = ObjectTypeExtensionNode({ * // properties... * }); * ``` */ export function ObjectTypeExtensionNode(props: Omit): ObjectTypeExtensionNode { return { type: TYPE, ...props }; }