Skip to content

Commit

Permalink
add schema-version for cache busting
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Oct 28, 2023
1 parent 33e8538 commit 6fda54a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/graphqlsp/src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function getGraphQLDiagnostics(
hasTSErrors: Boolean,
filename: string,
baseTypesPath: string,
schema: { current: GraphQLSchema | null },
schema: { current: GraphQLSchema | null; version: number },
info: ts.server.PluginCreateInfo
): ts.Diagnostic[] | undefined {
const logger = (msg: string) =>
Expand Down Expand Up @@ -78,7 +78,7 @@ export function getGraphQLDiagnostics(
});

let tsDiagnostics: ts.Diagnostic[] = [];
const cacheKey = fnv1a(texts.join('-'));
const cacheKey = fnv1a(texts.join('-') + schema.version);
if (cache.has(cacheKey)) {
tsDiagnostics = cache.get(cacheKey)!;
} else {
Expand Down
12 changes: 10 additions & 2 deletions packages/graphqlsp/src/graphql/getSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ export const loadSchema = (
shouldTypegen: boolean,
scalars: Record<string, unknown>,
extraTypes?: string
): { current: GraphQLSchema | null } => {
const ref: { current: GraphQLSchema | null } = { current: null };
): { current: GraphQLSchema | null; version: number } => {
const ref: { current: GraphQLSchema | null; version: number } = {
current: null,
version: 0,
};
let url: URL | undefined;

let isJSON = false;
Expand Down Expand Up @@ -77,6 +80,7 @@ export const loadSchema = (
ref.current = buildClientSchema(
(result as { data: IntrospectionQuery }).data
);
ref.version = ref.version + 1;
logger(`Got schema for ${url!.toString()}`);
if (shouldTypegen)
generateBaseTypes(
Expand All @@ -103,12 +107,16 @@ export const loadSchema = (
ref.current = isJson
? buildClientSchema(JSON.parse(contents))
: buildSchema(contents);
ref.version = ref.version + 1;

if (shouldTypegen) generateBaseTypes(ref.current, baseTypesPath, scalars);
});

ref.current = isJson
? buildClientSchema(JSON.parse(contents))
: buildSchema(contents);
ref.version = ref.version + 1;

if (shouldTypegen)
generateBaseTypes(ref.current, baseTypesPath, scalars, extraTypes);
logger(`Got schema and initialized watcher for ${schema}`);
Expand Down

0 comments on commit 6fda54a

Please sign in to comment.