Gorgon.js

Query Collocation

Query collocation can be a controversial topic and although we believe that collocating your queries/requests and other expensive calls to either be in the same file as the a component that calls it or next to it in the file system can greatly improve the developer experience.

Apollo describes the benefit as “Jumping directly to the query and keeping the component in sync with its data dependencies is a pleasure.”

Gorgon can simplify this strategy of collocation by overall reducing the amount of code required to cache, invalidate, and retrieve your cache into a single command.

import Gorgon from '@gorgonjs/gorgon';

const getTODO = async (id: number) => {
  return Gorgon.get(`todo/${id}`, async () => {
    return fetch(`https://jsonplaceholder.typicode.com/todos/${id}`)
      .then(response => response.json());
  }, 60 * 1000); // 1 minute
};