File tree 1 file changed +20
-4
lines changed
1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change 1
- import type { SchemaNodeKind } from '../nodes/types' ;
1
+ import { SchemaNodeKind } from '../nodes/types' ;
2
2
import type { SchemaFragment } from '../types' ;
3
3
import { isValidType } from './guards/isValidType' ;
4
4
import { inferType } from './inferType' ;
5
5
6
6
export function getTypes ( fragment : SchemaFragment ) : SchemaNodeKind [ ] | null {
7
+ const types : SchemaNodeKind [ ] = [ ] ;
8
+ let isNullable = false ;
9
+
10
+ if ( 'nullable' in fragment ) {
11
+ if ( fragment . nullable === true ) {
12
+ isNullable = true ;
13
+ }
14
+ }
7
15
if ( 'type' in fragment ) {
8
16
if ( Array . isArray ( fragment . type ) ) {
9
- return fragment . type . filter ( isValidType ) ;
17
+ types . push ( ... fragment . type . filter ( isValidType ) ) ;
10
18
} else if ( isValidType ( fragment . type ) ) {
11
- return [ fragment . type ] ;
19
+ types . push ( fragment . type ) ;
12
20
}
21
+ if ( isNullable && ! types . includes ( SchemaNodeKind . Null ) ) {
22
+ types . push ( SchemaNodeKind . Null ) ;
23
+ }
24
+ return types ;
13
25
}
14
26
15
27
const inferredType = inferType ( fragment ) ;
16
28
if ( inferredType !== null ) {
17
- return [ inferredType ] ;
29
+ types . push ( inferredType ) ;
30
+ if ( isNullable && ! types . includes ( SchemaNodeKind . Null ) ) {
31
+ types . push ( SchemaNodeKind . Null ) ;
32
+ }
33
+ return types ;
18
34
}
19
35
20
36
return null ;
You can’t perform that action at this time.
0 commit comments