55 * LICENSE file in the root directory of this source tree.
66 */
77
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' ;
188import {
199 ExplorerFieldDef ,
2010 useExplorerContext ,
2111 useSchemaContext ,
2212} 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' ;
2325
2426import Argument from './Argument' ;
25- import MarkdownContent from './MarkdownContent' ;
26- import TypeLink from './TypeLink' ;
2727import DefaultValue from './DefaultValue' ;
2828import FieldLink from './FieldLink' ;
29+ import MarkdownContent from './MarkdownContent' ;
30+ import TypeLink from './TypeLink' ;
2931
3032export default function TypeDoc ( ) {
3133 const { schema } = useSchemaContext ( { nonNull : true } ) ;
@@ -35,19 +37,19 @@ export default function TypeDoc() {
3537 const navItem = explorerNavStack [ explorerNavStack . length - 1 ] ;
3638 const type = navItem . def ;
3739
38- if ( ! schema || ! isType ( type ) ) {
40+ if ( ! schema || ! isNamedType ( type ) ) {
3941 return null ;
4042 }
4143
4244 let typesTitle : string | null = null ;
4345 let types : readonly ( GraphQLObjectType | GraphQLInterfaceType ) [ ] = [ ] ;
44- if ( type instanceof GraphQLUnionType ) {
46+ if ( isUnionType ( type ) ) {
4547 typesTitle = 'possible types' ;
4648 types = schema . getPossibleTypes ( type ) ;
47- } else if ( type instanceof GraphQLInterfaceType ) {
49+ } else if ( isInterfaceType ( type ) ) {
4850 typesTitle = 'implementations' ;
4951 types = schema . getPossibleTypes ( type ) ;
50- } else if ( type instanceof GraphQLObjectType ) {
52+ } else if ( isObjectType ( type ) ) {
5153 typesTitle = 'implements' ;
5254 types = type . getInterfaces ( ) ;
5355 }
@@ -110,7 +112,7 @@ export default function TypeDoc() {
110112
111113 let valuesDef : ReactNode ;
112114 let deprecatedValuesDef : ReactNode ;
113- if ( type instanceof GraphQLEnumType ) {
115+ if ( isEnumType ( type ) ) {
114116 const values = type . getValues ( ) ;
115117 valuesDef = (
116118 < div className = "doc-category" >
@@ -156,12 +158,12 @@ export default function TypeDoc() {
156158 ( 'description' in type && type . description ) || 'No Description'
157159 }
158160 />
159- { type instanceof GraphQLObjectType && typesDef }
161+ { isObjectType ( type ) && typesDef }
160162 { fieldsDef }
161163 { deprecatedFieldsDef }
162164 { valuesDef }
163165 { deprecatedValuesDef }
164- { ! ( type instanceof GraphQLObjectType ) && typesDef }
166+ { ! isObjectType ( type ) && typesDef }
165167 </ div >
166168 ) ;
167169}
0 commit comments