@@ -13,7 +13,6 @@ import {
1313 gqlRelated ,
1414 DiagnosticsResult ,
1515 FixableDiagnosticWithLocation ,
16- tsRelated ,
1716} from "./utils/DiagnosticError" ;
1817import { err , ok } from "./utils/Result" ;
1918import * as E from "./Errors" ;
@@ -30,20 +29,20 @@ export type DerivedResolverDefinition = {
3029 kind : "DERIVED_CONTEXT" ;
3130} ;
3231
33- export type NameDefinition =
34- | {
35- name : NameNode ;
36- kind :
37- | "TYPE "
38- | "INTERFACE "
39- | "UNION "
40- | "SCALAR "
41- | "INPUT_OBJECT "
42- | "ENUM "
43- | "CONTEXT"
44- | "INFO" ;
45- }
46- | DerivedResolverDefinition ;
32+ export type NameDefinition = {
33+ name : NameNode ;
34+ kind :
35+ | "TYPE"
36+ | "INTERFACE "
37+ | "UNION "
38+ | "SCALAR "
39+ | "INPUT_OBJECT "
40+ | "ENUM "
41+ | "CONTEXT "
42+ | "INFO" ;
43+ } ;
44+
45+ export type DeclarationDefinition = NameDefinition | DerivedResolverDefinition ;
4746
4847type TsIdentifier = number ;
4948
@@ -62,7 +61,8 @@ type TsIdentifier = number;
6261export class TypeContext {
6362 checker : ts . TypeChecker ;
6463
65- _declarationToName : Map < ts . Declaration , NameDefinition > = new Map ( ) ;
64+ _declarationToDefinition : Map < ts . Declaration , DeclarationDefinition > =
65+ new Map ( ) ;
6666 _unresolvedNodes : Map < TsIdentifier , ts . EntityName > = new Map ( ) ;
6767 _idToDeclaration : Map < TsIdentifier , ts . Declaration > = new Map ( ) ;
6868
@@ -76,15 +76,15 @@ export class TypeContext {
7676 self . _markUnresolvedType ( node , typeName ) ;
7777 }
7878 for ( const [ node , definition ] of snapshot . nameDefinitions ) {
79- self . _recordTypeName ( node , definition ) ;
79+ self . _recordDeclaration ( node , definition ) ;
8080 }
8181 for ( const [ definition , reference ] of snapshot . implicitNameDefinitions ) {
8282 const declaration = self . maybeTsDeclarationForTsName ( reference . typeName ) ;
8383 if ( declaration == null ) {
8484 errors . push ( tsErr ( reference . typeName , E . unresolvedTypeReference ( ) ) ) ;
8585 continue ;
8686 }
87- const existing = self . _declarationToName . get ( declaration ) ;
87+ const existing = self . _declarationToDefinition . get ( declaration ) ;
8888 if ( existing != null ) {
8989 errors . push (
9090 tsErr (
@@ -98,8 +98,7 @@ export class TypeContext {
9898 ) ;
9999 continue ;
100100 }
101-
102- self . _recordTypeName ( declaration , definition ) ;
101+ self . _recordDeclaration ( declaration , definition ) ;
103102 }
104103
105104 if ( errors . length > 0 ) {
@@ -114,18 +113,21 @@ export class TypeContext {
114113
115114 // Record that a GraphQL construct of type `kind` with the name `name` is
116115 // declared at `node`.
117- private _recordTypeName ( node : ts . Declaration , definition : NameDefinition ) {
116+ private _recordDeclaration (
117+ node : ts . Declaration ,
118+ definition : DeclarationDefinition ,
119+ ) {
118120 this . _idToDeclaration . set ( definition . name . tsIdentifier , node ) ;
119- this . _declarationToName . set ( node , definition ) ;
121+ this . _declarationToDefinition . set ( node , definition ) ;
120122 }
121123
122124 // Record that a type references `node`
123125 private _markUnresolvedType ( node : ts . EntityName , name : NameNode ) {
124126 this . _unresolvedNodes . set ( name . tsIdentifier , node ) ;
125127 }
126128
127- allNameDefinitions ( ) : Iterable < NameDefinition > {
128- return this . _declarationToName . values ( ) ;
129+ allDefinitions ( ) : Iterable < DeclarationDefinition > {
130+ return this . _declarationToDefinition . values ( ) ;
129131 }
130132
131133 findSymbolDeclaration ( startSymbol : ts . Symbol ) : ts . Declaration | null {
@@ -173,7 +175,9 @@ export class TypeContext {
173175 ) ;
174176 }
175177
176- const nameDefinition = this . _declarationToName . get ( declarationResult . value ) ;
178+ const nameDefinition = this . _declarationToDefinition . get (
179+ declarationResult . value ,
180+ ) ;
177181 if ( nameDefinition == null ) {
178182 return err ( gqlErr ( unresolved , E . unresolvedTypeReference ( ) ) ) ;
179183 }
@@ -194,12 +198,12 @@ export class TypeContext {
194198 if ( referenceNode == null ) return false ;
195199 const declaration = this . maybeTsDeclarationForTsName ( referenceNode ) ;
196200 if ( declaration == null ) return false ;
197- return this . _declarationToName . has ( declaration ) ;
201+ return this . _declarationToDefinition . has ( declaration ) ;
198202 }
199203
200204 gqlNameDefinitionForGqlName (
201205 nameNode : NameNode ,
202- ) : DiagnosticResult < NameDefinition > {
206+ ) : DiagnosticResult < DeclarationDefinition > {
203207 const referenceNode = this . getEntityName ( nameNode ) ;
204208 if ( referenceNode == null ) {
205209 throw new Error ( "Expected to find reference node for name node." ) ;
@@ -209,7 +213,7 @@ export class TypeContext {
209213 if ( declaration == null ) {
210214 return err ( gqlErr ( nameNode , E . unresolvedTypeReference ( ) ) ) ;
211215 }
212- const definition = this . _declarationToName . get ( declaration ) ;
216+ const definition = this . _declarationToDefinition . get ( declaration ) ;
213217 if ( definition == null ) {
214218 return err ( gqlErr ( nameNode , E . unresolvedTypeReference ( ) ) ) ;
215219 }
@@ -230,7 +234,9 @@ export class TypeContext {
230234 ) ;
231235 }
232236
233- const nameDefinition = this . _declarationToName . get ( declarationResult . value ) ;
237+ const nameDefinition = this . _declarationToDefinition . get (
238+ declarationResult . value ,
239+ ) ;
234240 if ( nameDefinition == null ) {
235241 return err ( tsErr ( node , E . unresolvedTypeReference ( ) ) ) ;
236242 }
0 commit comments