convoyinc/apollo-cache-hermes

Add better description of what a normalized graph cache is

jnak opened this issue · 1 comments

jnak commented

In the design exploration, it is not clear how the normalize graph is different than the regular flat map.

The examples look exactly the same:

  • flat map:
{
  ROOT: {
    posts: [
      { __ref: 1 },
      { __ref: 2 },
    ],
  },
  1: {
    id: 1,
    title: 'GraphQL Rocks!',
    author: { __ref: 3 },
  },
  2: {
    id: 2,
    title: 'GraphQL Rocks!',
    author: { __ref: 3 },
  },
  3: {
    id: 3,
    name: 'Gouda',
  },
}
  • normalized graph:
{
  ROOT: {
    posts: [
      {…}, // Reference to <1>
      {…}, // Reference to <2>
    ],
  },
  1: {
    id: 1,
    title: "GraphQL Rocks!",
    author: {…} // Reference to <3>
  },
  2: {
    id: 2,
    title: "Caching Is Hard",
    author: {…} // Reference to <3>
  },
  3: {
    id: 3,
    name: 'Gouda',
  },
}

Would you mind updating the description of the normalized graph cache?

nevir commented

Yeah, let me try explaining here to see where I'm missing info:

The main difference is that in the second example, ROOT.posts[0] maps to the exact same javascript object as 1. Whereas in the first example, that mapping is represented by an intermediate object (the { __ref: 1 }). Does that clarify?