@@ -16,17 +16,17 @@ import {
16
16
} from './directoryToAst' ;
17
17
import { FieldConfig } from './typeDefs' ;
18
18
19
- interface VisitInfoData < TContext = any > {
20
- node : AstDirNode | AstFileNode | AstRootTypeNode ;
19
+ interface VisitInfoData < TNode extends AstDirNode | AstFileNode | AstRootTypeNode , TContext = any > {
20
+ node : TNode ;
21
21
nodeParent : AstDirNode | AstRootTypeNode | AstRootNode ;
22
22
operation : RootTypeNames ;
23
23
fieldName : string ;
24
24
fieldPath : string [ ] ;
25
25
schemaComposer : SchemaComposer < TContext > ;
26
26
}
27
27
28
- export class VisitInfo < TContext = any > {
29
- node : AstDirNode | AstFileNode | AstRootTypeNode ;
28
+ export class VisitInfo < TNode extends AstDirNode | AstFileNode | AstRootTypeNode , TContext = any > {
29
+ node : TNode ;
30
30
/** Parent AST node from directoryToAst */
31
31
nodeParent : AstDirNode | AstRootTypeNode | AstRootNode ;
32
32
/** Brunch of schema under which is working visitor. Can be: query, mutation, subscription */
@@ -38,7 +38,7 @@ export class VisitInfo<TContext = any> {
38
38
/** Type registry */
39
39
schemaComposer : SchemaComposer < TContext > ;
40
40
41
- constructor ( data : VisitInfoData < TContext > ) {
41
+ constructor ( data : VisitInfoData < TNode , TContext > ) {
42
42
this . node = data . node ;
43
43
this . operation = data . operation ;
44
44
this . nodeParent = data . nodeParent ;
@@ -121,14 +121,13 @@ export class VisitInfo<TContext = any> {
121
121
* This is mutable object and is shared between all calls.
122
122
*/
123
123
get fieldConfig ( ) : FieldConfig {
124
- if ( this . node . kind === 'file' ) {
125
- return this . node . code ?. default as FieldConfig ;
126
- } else if ( this . node . kind === 'dir' || this . node . kind === 'rootType' ) {
127
- return this . node . namespaceConfig ?. code ?. default as FieldConfig ;
124
+ const node = this . node ;
125
+ if ( node . kind === 'file' ) {
126
+ return node . code ?. default as FieldConfig ;
127
+ } else if ( node . kind === 'dir' || this . node . kind === 'rootType' ) {
128
+ return node . namespaceConfig ?. code ?. default as FieldConfig ;
128
129
}
129
- throw new Error (
130
- `Cannot get fieldConfig. Node has some strange kind: ${ ( this . node as any ) . kind } `
131
- ) ;
130
+ throw new Error ( `Cannot get fieldConfig. Node has some strange kind: ${ node . kind } ` ) ;
132
131
}
133
132
134
133
/**
0 commit comments