Mirror: TypeScript LSP plugin that finds GraphQL documents in your code and provides diagnostics, auto-complete and hover-information.

chore: avoid bailing out of the cache for identical introspections (#193)

* avoid bailing out of the cache for identical introspections

* fix fixture

Changed files
+20 -5
.changeset
packages
graphqlsp
src
graphql
+5
.changeset/empty-students-press.md
···
+
---
+
'@0no-co/graphqlsp': patch
+
---
+
+
Avoid bailing out of the cache for identical introspections
+15 -5
packages/graphqlsp/src/graphql/getSchema.ts
···
tadaOutputLocation: string | undefined,
logger: Logger
): { current: GraphQLSchema | null; version: number } => {
-
const ref: { current: GraphQLSchema | null; version: number } = {
+
const ref: {
+
current: GraphQLSchema | null;
+
version: number;
+
prev: string | null;
+
} = {
current: null,
version: 0,
+
prev: null,
};
let url: URL | undefined;
let config: { headers: Record<string, unknown> } | undefined;
···
if (typeof result === 'string') {
logger(`Got error while fetching introspection ${result}`);
} else if (result.data) {
+
const introspection = (result as { data: IntrospectionQuery }).data;
+
const currentStringified = JSON.stringify(introspection);
+
if (ref.prev && ref.prev === currentStringified) {
+
return;
+
}
+
+
ref.prev = currentStringified;
try {
if (tadaOutputLocation) {
saveTadaIntrospection(
root,
-
result.data as IntrospectionQuery,
+
introspection,
tadaOutputLocation,
logger
);
}
-
ref.current = buildClientSchema(
-
(result as { data: IntrospectionQuery }).data
-
);
+
ref.current = buildClientSchema(introspection);
ref.version = ref.version + 1;
logger(`Got schema for ${url!.toString()}`);
} catch (e: any) {