3 ms·
You don’t have to get back JSON. My server allows EDN and YML as well as json. Also JSON as the query language would involve far more boilerplate and is ultimat
by ilikehurdles 8y ago
You don’t have to get back JSON. My server allows EDN and YML as well as json. Also JSON as the query language would involve far more boilerplate and is ultimately a machine language. How does JSON validate that a string is an ID and not a date or a breed of dog? It doesn’t. You need something to parse and check your JSON as well.
As for boilerplate for writing mutations... why do you say that’s needed? My clients’ queries and mutations are static and parameterized with variables, much like parameterized SQL queries. Just reuse the query/mutation and pass in a different map of parameters when you perform similar actions.
As for ORMs, well sure. We don’t use SQL but datomic is one of the DBs we use, and some of its schema is translated into the graphql schema. There’s also salesforce, elasticsearch, postgis, and existing pre-graphql APIs. The server handles the logic for joining the right results at the right points in the query. You’re seriously downplaying how nice it is for the client to not have to worry about client-side joins and getting exactly what they need. I can’t tell you how many times I’ve seen bugs in the wild because the client is trying to ask for an object out of a rest api using a ID of undefined or null because they’re in the middle of a join and thought they had data in hand. The schema prevents them from trying to ask for invalid relationships. And can make guarantees about availability. I also make available meta information such as result counts and page information so they know when to stop walking.
It’s usually pretty straightforward to reuse resolvers to meet the client’s ask, so if one client needs cars sold by dealership and another needs cars sold by state and another needs cars sold by salesperson, I can choose to support it all in the same handler by providing arguments they can all use, or I can expose it as a nested graph they can walk starting from any of these points.