import type { Node } from 'web-tree-sitter'; import type { DescriptionNode } from './description.js'; 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_definition' as const; // ================================================================ // ================================================================ // // ObjectTypeDefinitionNode // // GraphQL object type definition node // // ================================================================ // ================================================================ /** * Represents a object type definition in the GraphQL AST. * * Children: * {@link DescriptionNode}, {@link DirectivesNode}, {@link FieldsDefinitionNode}, {@link ImplementsInterfacesNode}, {@link NameNode} * */ export interface ObjectTypeDefinitionNode extends Node { type: typeof TYPE; } // ================================================================ // ================================================================ // // Type Guard // // ================================================================ // ================================================================ /** * Type guard to check if a node is a {@link ObjectTypeDefinitionNode}. * * @param node - The node to check * @returns True if the node is a {@link ObjectTypeDefinitionNode} * * @example * ```typescript * if (isObjectTypeDefinitionNode(node)) { * // TypeScript now knows node is ObjectTypeDefinitionNode * console.log(node.type); // 'object_type_definition' * } * ``` */ export function isObjectTypeDefinitionNode(node: unknown): node is ObjectTypeDefinitionNode { return (node as any)?.type === TYPE; } // ================================================================ // ================================================================ // // Constructor // // ================================================================ // ================================================================ /** * Creates a new {@link ObjectTypeDefinitionNode} with the specified properties. * * @param props - The node properties * @param props.description - {@link DescriptionNode} * @param props.directives - {@link DirectivesNode} * @param props.fieldsdefinition - {@link FieldsDefinitionNode} * @param props.implementsinterfaces - {@link ImplementsInterfacesNode} * @param props.name - {@link NameNode} * @returns A new {@link ObjectTypeDefinitionNode} * * @example * ```typescript * const node = ObjectTypeDefinitionNode({ * // properties... * }); * ``` */ export function ObjectTypeDefinitionNode(props: Omit): ObjectTypeDefinitionNode { return { type: TYPE, ...props }; }