Skip to content

Commit

Permalink
refactor the whole integration suite
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Feb 5, 2024
1 parent 3c0e268 commit c22b0c6
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 280 deletions.
71 changes: 9 additions & 62 deletions packages/graphql-language-service-server/src/GraphQLCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,32 +424,6 @@ export class GraphQLCache implements GraphQLCacheInterface {
return patterns;
};

async _updateGraphQLFileListCache(
graphQLFileMap: Map<Uri, GraphQLFileInfo>,
metrics: { size: number; mtime: number },
filePath: Uri,
exists: boolean,
): Promise<Map<Uri, GraphQLFileInfo>> {
const fileAndContent = exists
? await this.promiseToReadGraphQLFile(filePath)
: null;

const existingFile = graphQLFileMap.get(filePath);

// 3 cases for the cache invalidation: create/modify/delete.
// For create/modify, swap the existing entry if available;
// otherwise, just push in the new entry created.
// For delete, check `exists` and splice the file out.
if (existingFile && !exists) {
graphQLFileMap.delete(filePath);
} else if (fileAndContent) {
const graphQLFileInfo = { ...fileAndContent, ...metrics };
graphQLFileMap.set(filePath, graphQLFileInfo);
}

return graphQLFileMap;
}

async updateFragmentDefinition(
rootDir: Uri,
filePath: Uri,
Expand Down Expand Up @@ -490,32 +464,6 @@ export class GraphQLCache implements GraphQLCacheInterface {
}
}

async updateFragmentDefinitionCache(
rootDir: Uri,
filePath: Uri,
exists: boolean,
): Promise<void> {
const fileAndContent = exists
? await this.promiseToReadGraphQLFile(filePath)
: null;
// In the case of fragment definitions, the cache could just map the
// definition name to the parsed ast, whether or not it existed
// previously.
// For delete, remove the entry from the set.
if (!exists) {
const cache = this._fragmentDefinitionsCache.get(rootDir);
if (cache) {
cache.delete(filePath);
}
} else if (fileAndContent?.queries) {
await this.updateFragmentDefinition(
rootDir,
filePath,
fileAndContent.queries,
);
}
}

async updateObjectTypeDefinition(
rootDir: Uri,
filePath: Uri,
Expand Down Expand Up @@ -664,18 +612,17 @@ export class GraphQLCache implements GraphQLCacheInterface {
if (schemaPath && schemaKey) {
schemaCacheKey = schemaKey as string;

// Maybe use cache
// if (this._schemaMap.has(schemaCacheKey)) {
// schema = this._schemaMap.get(schemaCacheKey);
// if (schema) {
// return queryHasExtensions
// ? this._extendSchema(schema, schemaPath, schemaCacheKey)
// : schema;
// }
// }

// Read from disk
schema = await projectConfig.getSchema();

if (this._schemaMap.has(schemaCacheKey)) {
schema = this._schemaMap.get(schemaCacheKey);
if (schema) {
return queryHasExtensions
? this._extendSchema(schema, schemaPath, schemaCacheKey)
: schema;
}
}
}

const customDirectives = projectConfig?.extensions?.customDirectives;
Expand Down
15 changes: 6 additions & 9 deletions packages/graphql-language-service-server/src/MessageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export class MessageProcessor {

async handleDidOpenOrSaveNotification(
params: DidSaveTextDocumentParams | DidOpenTextDocumentParams,
): Promise<PublishDiagnosticsParams | null> {
): Promise<PublishDiagnosticsParams> {
/**
* Initialize the LSP server when the first file is opened or saved,
* so that we can access the user settings for config rootDir, etc
Expand All @@ -327,7 +327,7 @@ export class MessageProcessor {
// don't try to initialize again if we've already tried
// and the graphql config file or package.json entry isn't even there
if (this._isGraphQLConfigMissing === true && !isGraphQLConfigFile) {
return null;
return { uri: params.textDocument.uri, diagnostics: [] };
}
// then initial call to update graphql config
await this._updateGraphQLConfig();
Expand Down Expand Up @@ -360,13 +360,10 @@ export class MessageProcessor {
contents = this._parser(text, uri);

await this._invalidateCache(textDocument, uri, contents);
} else {
if (isGraphQLConfigFile) {
this._logger.info('updating graphql config');
await this._updateGraphQLConfig();
return { uri, diagnostics: [] };
}
return null;
} else if (isGraphQLConfigFile) {
this._logger.info('updating graphql config');
await this._updateGraphQLConfig();
return { uri, diagnostics: [] };
}
if (!this._graphQLCache) {
return { uri, diagnostics };
Expand Down

0 comments on commit c22b0c6

Please sign in to comment.