Skip to content

Instantly share code, notes, and snippets.

@domkm
domkm / machine.js
Last active April 14, 2020 16:55
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions

Synthetic IDs and cache normalization in Apollo 3

We are using Apollo 2 in production and are very happy with it. Thanks for developing it! :) Now that Apollo 3 is out, we tried to upgrade and ran into some issues with caching.

Apollo 3 seems to believe that it is practical to manually specify merge strategies for every type and/or field (hundreds or thousands of lines of configuration) and also that this manual configuration cannot be checked at build time or start time, but instead fail eventually at runtime. To me, this sounds like an unacceptable combination. Given this, I set about writing code to inspect our schema and generate type policies. However, I ran into issues with Apollo not exposing sufficient information to build these policies.

I believe that a simple and general normalization strategy is sufficient for our use and for the vast majority of non-pathologic schemas that make the following assumptions:

  1. Most objects have ids that allow normalization
  2. Objects that do not have ids a
@domkm
domkm / default.css
Last active January 9, 2021 16:09
Annotated LightTable Theme
/* LightTable themes are just CSS. LightTable, CodeMirror, and plugins apply
classes to tokens within the text. Most of these classes are undocumented. I
had to go fishing with the dev inspector and apply brightly colored rules to
figure it out. Hopefully I can save you the trouble by documenting the default
theme. Please comment if you find any errors or omissions. */
/* These #multi rules apply to tabsets. Active means currently selected and dirty
means that the file has been edited since the last save. */
#multi.theme-default .tabset .list .active { color:var(placeholder-fg); }
#multi.theme-default .tabset.active .list .active { color:var(highlight-fg); }
import SwiftData
import SwiftUI
@Model final class Parent {
init() {
child = Child()
}
@Transient let uuid = UUID()
@Relationship(deleteRule: .cascade, inverse: \Child.parent) var child: Child?