This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-04
Channels
- # 100-days-of-code (1)
- # announcements (1)
- # beginners (51)
- # boot (1)
- # calva (1)
- # cider (16)
- # cljsrn (2)
- # clojure (52)
- # clojure-spec (19)
- # clojure-uk (8)
- # clojurescript (8)
- # events (1)
- # figwheel-main (8)
- # fulcro (57)
- # midje (1)
- # nrepl (10)
- # off-topic (38)
- # pedestal (4)
- # portkey (1)
- # reagent (3)
- # reitit (4)
- # spacemacs (8)
@slipset Yea, that's the purpose. Why do you think REST is the wrong approach for this use case?
@rgb.ide Because a SPA is basically doing two things: It’s querying a database (through a proxy which is your backend). GraphQl and it’s likes are bette at this than vanilla REST. GraphQl lets the client decide the shape of the data it needs and also lets the client request all the data it needs in one request, avoiding the n + 1 problem. https://secure.phabricator.com/book/phabcontrib/article/n_plus_one/
The other thing it’s doing is issuing commands. Yes you can do this with REST, but I think you’ll see over the course of time that by thinking in terms of commands, the vocabulary of your system will appear. IMO REST mutability in REST is about mutating resources. When you need to mutate several resources in a transaction, REST is not a good fit.
The stupidest example, which can be refuted easily is “transfer funds between two accounts”
If you adopt this pattern implementing new commands on the backend is just a matter of adding another defmethod
to your (defmulti execute :command)
And it becomes quite clear what your application is about, since you’ve now enumerated all the commands available as implementations of the execute
function.
It’s especially beneficial when your schema grows and your entity graph is densely interconnected.
Here’s a list of publicly available APIs, have a play and see for yourself. https://github.com/APIs-guru/graphql-apis
(Happy to talk more about specifics when you have questions, I’ve been working on a graphql backend serving a huge graph from multiple datasources for the last 2 years)
@lady3janepl just so I understand. I was referring to n+1 between client and API, and that’s the n+1 problem I see GraphQL solving.
I’ve seen people are unaware about n+1 within the server, adopt the technology and get confused when they hit performance problems; so I wanted to make that specific.
We’ve ended up with a bunch of ad-hoc aggregated
REST-endpoints to “fix” the n+1 between client and server. Doesn’t really scale all that well.
All the companies that used it heavily that I know of had their own server implementation (that was not dataloader)
And yes, we have a bunch of n+1 problems on the server because we’ve composed our “fetch n things” out of a bunch of “fetch 1 thing”.
Facebook has TAO, shopify (I think) has something of their own as well although it’s more publicised.
One thing you can do in that case (if you want a quick solution to improving performance, and if you don’t want to faff with batching through dataloader) is log queries and check which ones come from your downstream(s) the most, and build in optimised solutions for those ones in particular. It’s a “discovery” approach similar to how public planning discovers where to put down asphalt pedestrian paths: check where people walk often enough to create visible tracks and then put a path there.
Is that how most people do it, or are solutions like join-monster
better suited to solve the n+1 problem b/w the server and the DB? (Assuming its a SQL DB)
Or pathom
+ walkable
in the clojure world.
But the last I've seen walkable still does table joins on the server.
As with everything in programming, I doubt there’s a good answer to how most people do it because it’s hard to know what goes on in closed projects 🙂 What I outlined above is a quick and universal solution.
I’d strongly caution against using anything that ties your graphql schema too tightly to your sql schema, or that generates graphql from sql.
(And I don’t have much experience with join monster because I’m stitching disparate data sources in different kinds of stores)
Perhaps d2q
will solve it:
https://github.com/vvvvalvalval/d2q
README sounds promising. Haven't checked it out still.