@@ -16,17 +16,17 @@ import {
1616} from './directoryToAst' ;
1717import { FieldConfig } from './typeDefs' ;
1818
19- interface VisitInfoData < TContext = any > {
20- node : AstDirNode | AstFileNode | AstRootTypeNode ;
19+ interface VisitInfoData < TNode extends AstDirNode | AstFileNode | AstRootTypeNode , TContext = any > {
20+ node : TNode ;
2121 nodeParent : AstDirNode | AstRootTypeNode | AstRootNode ;
2222 operation : RootTypeNames ;
2323 fieldName : string ;
2424 fieldPath : string [ ] ;
2525 schemaComposer : SchemaComposer < TContext > ;
2626}
2727
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 ;
3030 /** Parent AST node from directoryToAst */
3131 nodeParent : AstDirNode | AstRootTypeNode | AstRootNode ;
3232 /** Brunch of schema under which is working visitor. Can be: query, mutation, subscription */
@@ -38,7 +38,7 @@ export class VisitInfo<TContext = any> {
3838 /** Type registry */
3939 schemaComposer : SchemaComposer < TContext > ;
4040
41- constructor ( data : VisitInfoData < TContext > ) {
41+ constructor ( data : VisitInfoData < TNode , TContext > ) {
4242 this . node = data . node ;
4343 this . operation = data . operation ;
4444 this . nodeParent = data . nodeParent ;
@@ -121,14 +121,13 @@ export class VisitInfo<TContext = any> {
121121 * This is mutable object and is shared between all calls.
122122 */
123123 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 ;
128129 }
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 } ` ) ;
132131 }
133132
134133 /**
0 commit comments