import { InputObjectTypeDefinitionNode, InterfaceTypeDefinitionNode, NameNode, ObjectTypeDefinitionNode, UnionTypeDefinitionNode } from "graphql"; import * as ts from "typescript"; import { DiagnosticResult, DiagnosticsResult } from "./utils/DiagnosticError.js"; import { ExtractionSnapshot } from "./Extractor.js"; import { ResolverArgument } from "./resolverSignature.js"; export declare const UNRESOLVED_REFERENCE_NAME = "__UNRESOLVED_REFERENCE__"; export type DerivedResolverDefinition = { name: NameNode; path: string; exportName: string | null; args: ResolverArgument[]; kind: "DERIVED_CONTEXT"; async: boolean; }; export type NameDefinition = { name: NameNode; kind: "TYPE" | "INTERFACE" | "UNION" | "SCALAR" | "INPUT_OBJECT" | "ENUM" | "CONTEXT" | "INFO"; }; export type DeclarationDefinition = NameDefinition | DerivedResolverDefinition; /** * Public interface for TypeContext. * * Used to track TypeScript references and resolve type names between * TypeScript and GraphQL. */ export interface ITypeContext { /** Resolves an unresolved NameNode to its actual GraphQL name */ resolveUnresolvedNamedType(unresolved: NameNode): DiagnosticResult; /** Checks if an unresolved NameNode refers to a GraphQL type */ unresolvedNameIsGraphQL(unresolved: NameNode): boolean; /** Gets the declaration definition for a GraphQL NameNode */ gqlNameDefinitionForGqlName(nameNode: NameNode): DiagnosticResult; /** Gets the GraphQL name for a TypeScript entity name */ gqlNameForTsName(node: ts.EntityName): DiagnosticResult; } /** * Additional methods implemented by TypeContext for use during type resolution. */ export interface ITypeContextForResolveTypes extends ITypeContext { /** * Gets the TypeScript declaration for a TypeScript entity name. */ tsDeclarationForTsName(node: ts.EntityName): DiagnosticResult; /** * Gets the TypeScript declaration for a GraphQL definition node * Currently used exclusively for taking a GraphQL declaration and * finding its TypeScript declaration in order to find generic type * parameters. */ tsDeclarationForGqlDefinition(definition: ObjectTypeDefinitionNode | UnionTypeDefinitionNode | InputObjectTypeDefinitionNode | InterfaceTypeDefinitionNode): ts.Declaration; /** Gets the TypeScript entity name associated with a GraphQL NameNode */ getEntityName(name: NameNode): ts.EntityName | null; } /** * Used to track TypeScript references. * * If a TS method is typed as returning `MyType`, we need to look at that type's * GQLType annotation to find out its name. However, we may not have seen that * class yet. * * So, we employ a two pass approach. When we encounter a reference to a type * we model it as a dummy type reference in the GraphQL AST. Then, after we've * parsed all the files, we traverse the GraphQL schema, resolving all the dummy * type references. */ export declare class TypeContext implements ITypeContext, ITypeContextForResolveTypes { private checker; private _declarationToDefinition; private _unresolvedNodes; private _idToDeclaration; static fromSnapshot(checker: ts.TypeChecker, snapshot: ExtractionSnapshot): DiagnosticsResult; constructor(checker: ts.TypeChecker); private _recordDeclaration; private findSymbolDeclaration; private resolveSymbol; resolveUnresolvedNamedType(unresolved: NameNode): DiagnosticResult; unresolvedNameIsGraphQL(unresolved: NameNode): boolean; gqlNameDefinitionForGqlName(nameNode: NameNode): DiagnosticResult; gqlNameForTsName(node: ts.EntityName): DiagnosticResult; private maybeTsDeclarationForTsName; tsDeclarationForTsName(node: ts.EntityName): DiagnosticResult; tsDeclarationForGqlDefinition(definition: ObjectTypeDefinitionNode | UnionTypeDefinitionNode | InputObjectTypeDefinitionNode | InterfaceTypeDefinitionNode): ts.Declaration; getEntityName(name: NameNode): ts.EntityName | null; }