Skip to content

Commit

Permalink
fix: handle all types of graphql schema
Browse files Browse the repository at this point in the history
  • Loading branch information
simowe committed Jun 20, 2023
1 parent e044d3d commit 6f0f763
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions packages/graphql-language-service-server/src/MessageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1144,12 +1144,36 @@ export class MessageProcessor {
project: GraphQLProjectConfig,
uri: Uri,
): Promise<void> {
const { dirpath, schema } = project;
const schemaFilePath = path.resolve(dirpath, schema as string);
const uriFilePath = URI.parse(uri).fsPath;
if (uriFilePath === schemaFilePath) {
await this._graphQLCache.invalidateSchemaCacheForProject(project);
await Promise.all(
this._unwrapProjectSchema(project).map(async schema => {
const schemaFilePath = path.resolve(project.dirpath, schema);
const uriFilePath = URI.parse(uri).fsPath;
if (uriFilePath === schemaFilePath) {
await this._graphQLCache.invalidateSchemaCacheForProject(project);
}
}),
);
}

_unwrapProjectSchema(project: GraphQLProjectConfig): string[] {
const projectSchema = project.schema;

const schemas: string[] = [];
if (typeof projectSchema === 'string') {
schemas.push(projectSchema);
} else if (Array.isArray(projectSchema)) {
for (const schemaEntry of projectSchema) {
if (typeof schemaEntry === 'string') {
schemas.push(schemaEntry);
} else if (schemaEntry) {
schemas.push(...Object.keys(schemaEntry));
}
}
} else {
schemas.push(...Object.keys(projectSchema));
}

return schemas;
}

async _updateObjectTypeDefinition(
Expand Down

0 comments on commit 6f0f763

Please sign in to comment.