5
5
* LICENSE file in the root directory of this source tree.
6
6
*/
7
7
8
- import React , { ReactNode , useState } from 'react' ;
9
- import {
10
- GraphQLObjectType ,
11
- GraphQLInterfaceType ,
12
- GraphQLUnionType ,
13
- GraphQLEnumType ,
14
- GraphQLEnumValue ,
15
- GraphQLNamedType ,
16
- isType ,
17
- } from 'graphql' ;
18
8
import {
19
9
ExplorerFieldDef ,
20
10
useExplorerContext ,
21
11
useSchemaContext ,
22
12
} from '@graphiql/react' ;
13
+ import {
14
+ GraphQLEnumValue ,
15
+ GraphQLInterfaceType ,
16
+ GraphQLNamedType ,
17
+ GraphQLObjectType ,
18
+ isEnumType ,
19
+ isInterfaceType ,
20
+ isNamedType ,
21
+ isObjectType ,
22
+ isUnionType ,
23
+ } from 'graphql' ;
24
+ import React , { ReactNode , useState } from 'react' ;
23
25
24
26
import Argument from './Argument' ;
25
- import MarkdownContent from './MarkdownContent' ;
26
- import TypeLink from './TypeLink' ;
27
27
import DefaultValue from './DefaultValue' ;
28
28
import FieldLink from './FieldLink' ;
29
+ import MarkdownContent from './MarkdownContent' ;
30
+ import TypeLink from './TypeLink' ;
29
31
30
32
export default function TypeDoc ( ) {
31
33
const { schema } = useSchemaContext ( { nonNull : true } ) ;
@@ -35,19 +37,19 @@ export default function TypeDoc() {
35
37
const navItem = explorerNavStack [ explorerNavStack . length - 1 ] ;
36
38
const type = navItem . def ;
37
39
38
- if ( ! schema || ! isType ( type ) ) {
40
+ if ( ! schema || ! isNamedType ( type ) ) {
39
41
return null ;
40
42
}
41
43
42
44
let typesTitle : string | null = null ;
43
45
let types : readonly ( GraphQLObjectType | GraphQLInterfaceType ) [ ] = [ ] ;
44
- if ( type instanceof GraphQLUnionType ) {
46
+ if ( isUnionType ( type ) ) {
45
47
typesTitle = 'possible types' ;
46
48
types = schema . getPossibleTypes ( type ) ;
47
- } else if ( type instanceof GraphQLInterfaceType ) {
49
+ } else if ( isInterfaceType ( type ) ) {
48
50
typesTitle = 'implementations' ;
49
51
types = schema . getPossibleTypes ( type ) ;
50
- } else if ( type instanceof GraphQLObjectType ) {
52
+ } else if ( isObjectType ( type ) ) {
51
53
typesTitle = 'implements' ;
52
54
types = type . getInterfaces ( ) ;
53
55
}
@@ -110,7 +112,7 @@ export default function TypeDoc() {
110
112
111
113
let valuesDef : ReactNode ;
112
114
let deprecatedValuesDef : ReactNode ;
113
- if ( type instanceof GraphQLEnumType ) {
115
+ if ( isEnumType ( type ) ) {
114
116
const values = type . getValues ( ) ;
115
117
valuesDef = (
116
118
< div className = "doc-category" >
@@ -156,12 +158,12 @@ export default function TypeDoc() {
156
158
( 'description' in type && type . description ) || 'No Description'
157
159
}
158
160
/>
159
- { type instanceof GraphQLObjectType && typesDef }
161
+ { isObjectType ( type ) && typesDef }
160
162
{ fieldsDef }
161
163
{ deprecatedFieldsDef }
162
164
{ valuesDef }
163
165
{ deprecatedValuesDef }
164
- { ! ( type instanceof GraphQLObjectType ) && typesDef }
166
+ { ! isObjectType ( type ) && typesDef }
165
167
</ div >
166
168
) ;
167
169
}
0 commit comments