UNPKG

polen

Version:

A framework for delightful GraphQL developer portals

33 lines 1.79 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { Text } from '@radix-ui/themes'; import { isInputObjectType, isListType, isNamedType, isNonNullType, isScalarType } from 'graphql'; import { Link } from './Link.js'; /** * Renders a GraphQL type recursively, with links for named types */ export const TypeAnnotation = ({ type }) => { // Handle NonNull type wrapper if (isNonNullType(type)) { return (_jsxs(_Fragment, { children: [_jsx(TypeAnnotation, { type: type.ofType }), _jsx(Text, { color: 'gray', children: "!" })] })); } // Handle List type wrapper if (isListType(type)) { return (_jsxs(_Fragment, { children: [_jsx(Text, { color: 'gray', children: "[" }), _jsx(TypeAnnotation, { type: type.ofType }), _jsx(Text, { color: 'gray', children: "]" })] })); } // Handle named types if (isNamedType(type)) { const namedType = type; // Handle input object types if (isInputObjectType(namedType)) { return (_jsx(Link, { to: `/reference/${namedType.name}`, children: _jsx(Text, { color: 'green', children: namedType.name }) })); } // If it's an expandable type (object or interface), make it a link // if (Grafaid.isExpandableType(namedType)) { return (_jsx(Link, { to: `/reference/${namedType.name}`, children: _jsx(Text, { color: isScalarType(namedType) ? `purple` : `blue`, children: namedType.name }) })); // For scalar and other non-expandable types, just render the name // return <Text color="purple">{namedType.name}</Text> } // Fallback for any other case (shouldn't happen in standard GraphQL usage) return _jsx(Text, { children: String(type) }); }; //# sourceMappingURL=TypeAnnotation.js.map