apollo-cache-hermes icon indicating copy to clipboard operation
apollo-cache-hermes copied to clipboard

Add better description of what a normalized graph cache is

Open jnak opened this issue 6 years ago • 1 comments

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?

jnak avatar Oct 15 '18 22:10 jnak

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?

nevir avatar Oct 31 '18 22:10 nevir