INNER CODE UNIT · JavaScript

inflate

gajus/graphql-deduplicator · src/inflate.js:6

const inflate = (node: NodeType, index: Object, path: $ReadOnlyArray<string>): NodeType => {
  if (Array.isArray(node)) {
    return node.map((childNode) => {
      if (typeof childNode === 'string' || typeof childNode === 'number' || typeof childNode === 'boolean') {
        return childNode;
      } else {
        return inflate(childNode, index, path);
      }
    });
  } else {
    const route = path.join(',');
    if (node && node.id && node.__typename) {
      if (index[route] && index[route][node.__typename] && index[route][node.__typename][node.id]) {
        return index[route][node.__typename][node.id];
      }
    }
    const fieldNames = Object.keys(node);
    const result = {};

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…