| 116 | } |
| 117 | |
| 118 | export class GraphQLCache { |
| 119 | _configDir: Uri; |
| 120 | _graphQLFileListCache: Map<Uri, Map<string, GraphQLFileInfo>>; |
| 121 | _graphQLConfig: GraphQLConfig; |
| 122 | _schemaMap: Map<Uri, GraphQLSchema>; |
| 123 | _typeExtensionMap: Map<Uri, number>; |
| 124 | _fragmentDefinitionsCache: Map<Uri, Map<string, FragmentInfo>>; |
| 125 | _typeDefinitionsCache: Map<Uri, Map<string, ObjectTypeInfo>>; |
| 126 | _parser: typeof parseDocument; |
| 127 | _logger: Logger | NoopLogger; |
| 128 | _onSchemaChange?: OnSchemaChange; |
| 129 | _schemaCacheTTL?: number; |
| 130 | |
| 131 | constructor({ |
| 132 | configDir, |
| 133 | config, |
| 134 | parser, |
| 135 | logger, |
| 136 | onSchemaChange, |
| 137 | schemaCacheTTL, |
| 138 | }: { |
| 139 | configDir: Uri; |
| 140 | config: GraphQLConfig; |
| 141 | parser: typeof parseDocument; |
| 142 | logger: Logger | NoopLogger; |
| 143 | onSchemaChange?: OnSchemaChange; |
| 144 | schemaCacheTTL?: number; |
| 145 | }) { |
| 146 | this._configDir = configDir; |
| 147 | this._graphQLConfig = config; |
| 148 | this._graphQLFileListCache = new Map(); |
| 149 | this._schemaMap = new LRUCache({ |
| 150 | max: 20, |
| 151 | ttl: schemaCacheTTL ?? 1000 * 30, |
| 152 | ttlAutopurge: true, |
| 153 | updateAgeOnGet: false, |
| 154 | }); |
| 155 | this._fragmentDefinitionsCache = new Map(); |
| 156 | this._typeDefinitionsCache = new Map(); |
| 157 | this._typeExtensionMap = new Map(); |
| 158 | this._parser = parser; |
| 159 | this._logger = logger; |
| 160 | this._onSchemaChange = onSchemaChange; |
| 161 | } |
| 162 | |
| 163 | getGraphQLConfig = (): GraphQLConfig => this._graphQLConfig; |
| 164 | |
| 165 | getProjectForFile = (uri: string): GraphQLProjectConfig | void => { |
| 166 | try { |
| 167 | const project = this._graphQLConfig.getProjectForFile( |
| 168 | URI.parse(uri).fsPath, |
| 169 | ); |
| 170 | if (!project.documents) { |
| 171 | this._logger.warn( |
| 172 | `No documents configured for project ${project.name}. Many features will not work correctly.`, |
| 173 | ); |
| 174 | } |
| 175 | return project; |
nothing calls this directly
no test coverage detected