···
198
+
const allAccess: string[] = [];
199
+
const inProgress: string[] = [];
200
+
const allPaths: string[] = [];
201
+
const allFields: string[] = [];
202
+
const reserved = ['id', '__typename'];
203
+
const fieldToLoc = new Map<string, { start: number; length: number }>();
204
+
// This visitor gets all the leaf-paths in the document
205
+
// as well as all fields that are part of the document
206
+
// We need the leaf-paths to check usage and we need the
207
+
// fields to validate whether an access on a given reference
208
+
// is valid given the current document...
209
+
visit(parse(node.getText().slice(1, -1)), {
212
+
if (!reserved.includes(node.name.value)) {
213
+
allFields.push(node.name.value);
216
+
if (!node.selectionSet && !reserved.includes(node.name.value)) {
218
+
if (inProgress.length) {
219
+
p = inProgress.join('.') + '.' + node.name.value;
221
+
p = node.name.value;
225
+
fieldToLoc.set(p, {
226
+
start: node.name.loc!.start,
227
+
length: node.name.loc!.end - node.name.loc!.start,
229
+
} else if (node.selectionSet) {
230
+
inProgress.push(node.name.value);
234
+
if (node.selectionSet) {
references.forEach(ref => {
if (ref.fileName !== source.fileName) return;
···
if (output.name.getText() === variableDeclaration.name.getText()) return;
212
-
const inProgress: string[] = [];
213
-
const allPaths: string[] = [];
214
-
const allFields: string[] = [];
215
-
const reserved = ['id', '__typename'];
216
-
const fieldToLoc = new Map<string, { start: number; length: number }>();
217
-
// This visitor gets all the leaf-paths in the document
218
-
// as well as all fields that are part of the document
219
-
// We need the leaf-paths to check usage and we need the
220
-
// fields to validate whether an access on a given reference
221
-
// is valid given the current document...
222
-
visit(parse(node.getText().slice(1, -1)), {
225
-
if (!reserved.includes(node.name.value)) {
226
-
allFields.push(node.name.value);
229
-
if (!node.selectionSet && !reserved.includes(node.name.value)) {
231
-
if (inProgress.length) {
232
-
p = inProgress.join('.') + '.' + node.name.value;
234
-
p = node.name.value;
238
-
fieldToLoc.set(p, {
239
-
start: node.name.loc!.start,
240
-
length: node.name.loc!.end - node.name.loc!.start,
242
-
} else if (node.selectionSet) {
243
-
inProgress.push(node.name.value);
247
-
if (node.selectionSet) {
// - const result = await client.query() || useFragment()
···
temp = temp.elements[0].name;
269
-
let allAccess: string[] = [];
if (ts.isObjectBindingPattern(temp)) {
271
-
allAccess = traverseDestructuring(temp, [], allFields, source, info);
271
+
const result = traverseDestructuring(temp, [], allFields, source, info);
272
+
allAccess.push(...result);
273
-
allAccess = crawlScope(temp, [], allFields, source, info);
274
+
const result = crawlScope(temp, [], allFields, source, info);
275
+
allAccess.push(...result);
276
-
const unused = allPaths.filter(x => !allAccess.includes(x));
277
-
unused.forEach(unusedField => {
278
-
const loc = fieldToLoc.get(unusedField);
279
+
const unused = allPaths.filter(x => !allAccess.includes(x));
281
+
unused.forEach(unusedField => {
282
+
const loc = fieldToLoc.get(unusedField);
283
-
length: loc.length,
284
-
start: node.getStart() + loc.start + 1,
285
-
category: ts.DiagnosticCategory.Warning,
286
-
code: UNUSED_FIELD_CODE,
287
-
messageText: `Field '${unusedField}' is not used.`,
287
+
length: loc.length,
288
+
start: node.getStart() + loc.start + 1,
289
+
category: ts.DiagnosticCategory.Warning,
290
+
code: UNUSED_FIELD_CODE,
291
+
messageText: `Field '${unusedField}' is not used.`,