1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { useExplorerContext } from '@graphiql/react';
|
9 | import { GraphQLType, isListType, isNonNullType } from 'graphql';
|
10 | import React from 'react';
|
11 |
|
12 | type TypeLinkProps = {
|
13 | type: GraphQLType;
|
14 | };
|
15 |
|
16 | export default function TypeLink(props: TypeLinkProps) {
|
17 | const { push } = useExplorerContext({ nonNull: true, caller: TypeLink });
|
18 |
|
19 | if (!props.type) {
|
20 | return null;
|
21 | }
|
22 |
|
23 | const type = props.type;
|
24 | if (isNonNullType(type)) {
|
25 | return (
|
26 | <>
|
27 | <TypeLink type={type.ofType} />!
|
28 | </>
|
29 | );
|
30 | }
|
31 | if (isListType(type)) {
|
32 | return (
|
33 | <>
|
34 | [<TypeLink type={type.ofType} />]
|
35 | </>
|
36 | );
|
37 | }
|
38 | return (
|
39 | <a
|
40 | className="type-name"
|
41 | onClick={event => {
|
42 | event.preventDefault();
|
43 | push({ name: type.name, def: type });
|
44 | }}
|
45 | href="#"
|
46 | >
|
47 | {type.name}
|
48 | </a>
|
49 | );
|
50 | }
|