Skip to content

Instantly share code, notes, and snippets.

View RAMPKORV's full-sized avatar

RAMPKORV RAMPKORV

  • Reguity Group AB
  • Gothenburg, Sweden
View GitHub Profile
Promise.prototype.chunk = (arr, n) => Array.from({
length: Math.ceil(arr.length / n)
}, (v, i) => arr.slice(i * n, i * n + n))
.reduce((ack, c) => ack.then(async () => await Promise.all(c)), Promise.all([]));
const squel = require("squel");
const and = (...args) => squel.expr().and(...args);
const or = (...args) => squel.expr().or(...args);
Array(100).fill([['l','k'],['u'],['n','k'],['a'],['r']]).map(i=>i.map(j=>j.length>1?j[Math.random()>.5?0:1]:j[0]).join('')).join(' ');
@RAMPKORV
RAMPKORV / getRequestedFields.js
Created September 9, 2020 19:47
Parse ASTInfo to determine which of a set of GraphQL fields that have been requested
/* Given a list of fields, such as [ 'a', 'b', 'c' ] and ASTInfo, return an object
on the form {a: true, b: false, c: true } where a property is true if the field is requested through the ASTInfo */
const getRequestedFields = (fieldNames, info) => {
let { fieldNodes, fragments } = info;
let result = {};
for (let i = 0; i < fieldNodes.length; i++) {
if (!fieldNodes[i].selectionSet) {
continue;
}
for (let j = 0; j < fieldNodes[i].selectionSet.selections.length; j++) {