3 ms·
For those not familiar, check out Postgraphile.
by recursive4 5y ago
For those not familiar, check out Postgraphile.
- rattray 5y agoCame here to say this. To expound a bit, you can use it as a highly pluggable/extensible express plugin which you can point at any postgres db and get all CRUD and other operations exposed in GraphQL, without writing any code. You can easily hide or rename fields that you don't want exposed, override their behavior in Node, and add generated columns or fancy SQL mutations either in JS or directly in your DB and have them exposed as you'd expect in GQL. With a commonly-used plugin, you can even do rich ORM-like queries directly from graphql, like: query { allPeople(filter: { firstName: { startsWith:"John" } }) { nodes { firstName lastName posts(filter: { createdAt: { greaterThan: "2016-01-01" } }) { nodes { title body } } } } } More examples here: https://github.com/graphile-contrib/postgraphile-plugin-connection-filter#examples https://github.com/graphile-contrib/postgraphile-plugin-conn... (Personally, I think their docs are good at telling you how to use it but fairly bad at showing how great the tool is)
- vaughan 5y agoBut what about optimistic UI updates or offline support in the client. The frontend has no notion of the relationships between the entities, which means you will be making a lot more queries than you need to, or just ignoring optimistic updates (we may be fine for some apps).
- rattray 5y agoAs you note in your article, Apollo's gql client has optimistic UI, but it looks like a pain. The Apollo cache seems to be powerful enough normalize the way you want, perhaps with some extra code: https://www.apollographql.com/docs/react/caching/cache-configuration/ https://www.apollographql.com/docs/react/caching/cache-confi... Apollo also claims support for cache persistence, eg to localstorage: https://www.apollographql.com/docs/react/caching/advanced-topics/#cache-persistence https://www.apollographql.com/docs/react/caching/advanced-to... I haven't used Apollo myself so maybe it's not as usable or powerful as it claims to be.