Skip to content

Instantly share code, notes, and snippets.

View derrh's full-sized avatar

Derrick Hathaway derrh

View GitHub Profile
@derrh
derrh / SwiftUI+GraphQL.md
Created October 16, 2023 19:53
GraphQL + SwiftUI: Declarative Data and Declarative UI

Imagining what the future might be like with direct support for GraphQL in SwiftUI.

Rationale

SwiftUI and GraphQL both represent new paradigms, these new paradigms—when paired together—offer an unparalleled, streamlined, client development experience. Today the most widely used and robust Swift GraphQL clients lack direct SwiftUI support, as well as support for #8 and #9 of Jordan Eldridge's "GraphQL Maturity Model".

Goals

  • Each View declares it's data requirements using Fragments
  • Each View observes it's fragment data from the GraphQL normalized cache, limiting large-tree re-renders
  • Sensible defaults for cache policies and other configuration cover most cases, but can be overridden in intuitive ways
  • As Views are decomposed into subviews, queries are decomposed into fragments