import { Text } from '@radix-ui/themes' import type { GraphQLType } from 'graphql' import { isInputObjectType, isListType, isNamedType, isNonNullType, isScalarType } from 'graphql' import type { FC } from 'react' import { Link } from './Link.js' export interface Props { type: GraphQLType // Can be either GraphQLInputType or GraphQLOutputType } /** * Renders a GraphQL type recursively, with links for named types */ export const TypeAnnotation: FC = ({ type }) => { // Handle NonNull type wrapper if (isNonNullType(type)) { return ( <> ! ) } // Handle List type wrapper if (isListType(type)) { return ( <> [ ] ) } // Handle named types if (isNamedType(type)) { const namedType = type // Handle input object types if (isInputObjectType(namedType)) { return ( {namedType.name} ) } // If it's an expandable type (object or interface), make it a link // if (Grafaid.isExpandableType(namedType)) { return ( {namedType.name} ) // For scalar and other non-expandable types, just render the name // return {namedType.name} } // Fallback for any other case (shouldn't happen in standard GraphQL usage) return {String(type)} }