···
export const MISSING_OPERATION_NAME_CODE = 52002;
export const USING_DEPRECATED_FIELD_CODE = 52004;
46
-
let isGeneratingTypes = false;
const cache = new LRUCache<number, ts.Diagnostic[]>({
// how long to live in ms
···
: texts.join('-') + schema.version
if (cache.has(cacheKey)) {
99
-
return cache.get(cacheKey)!;
98
+
tsDiagnostics = cache.get(cacheKey)!;
101
-
const tsDiagnostics = runDiagnostics(
103
-
{ nodes, fragments },
100
+
tsDiagnostics = runDiagnostics(source, { nodes, fragments }, schema, info);
cache.set(cacheKey, tsDiagnostics);
104
+
const shouldCheckForColocatedFragments =
105
+
info.config.shouldCheckForColocatedFragments ?? true;
106
+
let fragmentDiagnostics: ts.Diagnostic[] = [];
107
+
if (isCallExpression && shouldCheckForColocatedFragments) {
108
+
const moduleSpecifierToFragments = getColocatedFragmentNames(source, info);
110
+
const usedFragments = new Set();
111
+
nodes.forEach(node => {
113
+
const parsed = parse(node.getText().slice(1, -1), {
117
+
FragmentSpread: node => {
118
+
usedFragments.add(node.name.value);
124
+
Object.keys(moduleSpecifierToFragments).forEach(moduleSpecifier => {
126
+
fragments: fragmentNames,
129
+
} = moduleSpecifierToFragments[moduleSpecifier];
130
+
const missingFragments = Array.from(
131
+
new Set(fragmentNames.filter(x => !usedFragments.has(x)))
133
+
if (missingFragments.length) {
134
+
fragmentDiagnostics.push({
138
+
category: ts.DiagnosticCategory.Warning,
139
+
code: MISSING_FRAGMENT_CODE,
140
+
messageText: `Unused co-located fragment definition(s) "${missingFragments.join(
142
+
)}" in ${moduleSpecifier}`,
147
+
return [...tsDiagnostics, ...fragmentDiagnostics];
···
307
-
const shouldCheckForColocatedFragments =
308
-
info.config.shouldCheckForColocatedFragments ?? true;
309
-
let fragmentDiagnostics: ts.Diagnostic[] = [];
310
-
if (shouldCheckForColocatedFragments) {
311
-
const moduleSpecifierToFragments = getColocatedFragmentNames(
316
-
const usedFragments = new Set();
317
-
nodes.forEach(node => {
319
-
const parsed = parse(node.getText().slice(1, -1), {
323
-
FragmentSpread: node => {
324
-
usedFragments.add(node.name.value);
330
-
Object.keys(moduleSpecifierToFragments).forEach(moduleSpecifier => {
332
-
fragments: fragmentNames,
335
-
} = moduleSpecifierToFragments[moduleSpecifier];
336
-
const missingFragments = Array.from(
337
-
new Set(fragmentNames.filter(x => !usedFragments.has(x)))
339
-
if (missingFragments.length) {
340
-
fragmentDiagnostics.push({
344
-
category: ts.DiagnosticCategory.Warning,
345
-
code: MISSING_FRAGMENT_CODE,
346
-
messageText: `Unused co-located fragment definition(s) "${missingFragments.join(
348
-
)}" in ${moduleSpecifier}`,
354
-
return [...tsDiagnostics, ...usageDiagnostics, ...fragmentDiagnostics];
348
+
return [...tsDiagnostics, ...usageDiagnostics];