Created
January 12, 2022 17:25
-
-
Save dwelch2344/c86287c4d3eee5a36659f1cd665a95db to your computer and use it in GitHub Desktop.
Search Apollo GraphQL Fields report for active fields in last 24 hours
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// inject jquery | |
(function (){ function l(u, i) { var d = document; if (!d.getElementById(i)) { var s = d.createElement('script'); s.src = u; s.id = i; d.body.appendChild(s); } } l('//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js', 'jquery') })(); | |
const runReport = () => { | |
$ = jQuery | |
// get all the rows with 0 calls and remove htem | |
targets = $('span.flex.items-center ').toArray().map($) | |
targets.filter(e => parseInt(e.html()) === 0).forEach(e => e.closest('tr').remove()) | |
// get all the remaining rows | |
targets = $('span.flex.items-center ').toArray().map($) | |
// keep an array by "object.field" count | |
sorted = {} | |
mapped = targets.map(target => { | |
// get the first column's spans (to strip out the field) | |
const spans = target.closest('tr').children().first().find('.truncate span').toArray().map($) | |
return { | |
section: target.closest('section').find(' > div').find('h2 > div').text().replace('anchor: ', ''), | |
field: spans[0].attr('title'), | |
returnValue: spans[1].find('a').html(), | |
calls: parseInt(target.html()), | |
} | |
}).reduce( (acc, val) => { | |
const [type] = val.section.split(' ') | |
sorted[`${type}.${val.field}`] = val.calls | |
const section = acc[val.section] || {} | |
section[val.field] = { | |
returns: val.returnValue, | |
calls: val.calls | |
} | |
acc[val.section] = section | |
return acc | |
}, {}) | |
pretty = Object.keys(sorted) | |
.map(key => ({ key, value: sorted[key]})) | |
.sort( (a, b) => b.value - a.value) | |
.map(row => `${row.key}: ${row.value}`) | |
.join('\n') | |
console.log({ sorted, mapped }, pretty) | |
} | |
setTimeout(runReport, 3 * 1000) // give jquery time to load |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment