magento / architecture

A place where Magento architectural discussions happen
274 stars 154 forks source link

MC-36347: ID Improvement Plan #415

Closed DrewML closed 4 years ago

DrewML commented 4 years ago

Rendered Document

sirugh commented 4 years ago

This is going to be very important for the client. By default, ApolloClient overwrites existing data with incoming data if there is no identifier for the data. A good example of this is two queries that fetch some subset of shipping_addresses.

# query 1
shipping_addresses {
  firstname
  lastname
}

# query 2
shipping_addresses {
  city
  street
  postcode
}

The last query to be processed will have its data stored in the cache (although a custom merge function can be defined)). For example if query 2 resolves after query 1 then even though we've already fetched firstname and lastname, the first query will require a new network round trip to resolve. Defining a custom merge function is an option but it requires a lot of overhead on the front end. For example, we can require that all queries for shipping_addresses fetch some uniquely identifying combination of fields, but that's essentially just the same thing as using those values to hash an id on the server.

As one of our core tenants in PWA is offline capability, serving from cache when possible is quite important, and it'd be preferable to have merging handled automatically via id rather than having to define custom merge functions for each field that doesn't expose one.