4 ms·
You're welcome! It was a pleasure to share. I like GraphQL because it aligns with how I think about frontend queries and data. I had spent a bunch of time with
by dmitryminkovsky 5y ago
You're welcome! It was a pleasure to share.
I like GraphQL because it aligns with how I think about frontend queries and data. I had spent a bunch of time with technologies like HATEOS that standardize sorta-similar REST-based approaches, but as soon as I saw GraphQL, in my mind it was immediately like: "THIS! This is it." There's just something about it for me. I can't say that that GraphQL is _important_ technologically, I'm sure I could have done it some other way, but it definitely is what has felt the most right of all other things I've tried, and I think that's really important. The front-end clients for GraphQL are also awesome. I've tried Relay and Apollo, and both are excellent. They normalize everything and provide reactive updates when something changes.
> For example, if your client makes the same dozen or so queries day-after-day, would it ever make sense to use that knowledge to write a more static API?
Hasura lets you turn GraphQL queries in REST endpoints! It's pretty amazing. But GraphQL also has this thing called "persisted queries" where instead of sending the queries every time that needs to be parsed, you send a hash for the queries, and the server already knows what the query is and has its representation stored in memory so it can satisfying it w/ the parse step. I can only hope to have to optimize like this :).
> Is computer time and space too inexpensive to worry about these things?
I don't think so... I've just been trying to ship without prematurely optimizing. It's been somewhat of a journey as it is :).
- criddell 5y agoThanks again. I didn't know about persisted queries but that sounds exactly like the answer to my question.
- dmitryminkovsky 5y agoYou're welcome! A small correction: I shouldn't have said that "GraphQL has persisted queries"—they're not part of the spec or something. Just something many tools allow/enable. And by the way, in 2021, I wouldn't write a GraphQL backend by hand. I think a tool like Hasura/Postgraphile is the way to go. They put up excellent scaffolds that you can augment. In addition Hasura (I don't know about other tools) provides an access control layer that is really nice as well.
- criddell 5y agoFunny you should mention access control. One of the stumbling blocks for me when I did a bit of GraphQL work was adhering to the best practices listed here: https://graphql.org/learn/authorization/ https://graphql.org/learn/authorization/ That says authorization should not be in the resolver but putting it elsewhere often resulted in much more complicated code. It makes sense if GraphQL is coexisting with REST or other end points because they could all share the same authentication code, but for pure GraphQL projects it seems arbitrary.
- dmitryminkovsky 5y agoYes those docs bewildered me a bit as well. I never got too far with all of that or building a GraphQL server in JS for that matter. The authorization/access control in Hasura is game changing.