5 ms·
> GraphQL is a great experience when you consume it and the service fulfills your query needs. Because you just ask stuff and you get them. It's really cool. I
by masklinn 5y ago
> GraphQL is a great experience when you consume it and the service fulfills your query needs. Because you just ask stuff and you get them. It's really cool.
I guess it's better when the tooling you use has direct gql integration and builds the queries for you?
Because in my experience accessing the github APIs with "basic" HTTP libraries is way more annoying using v4 (graphql) than v3 ("rest") — it could also be that github's v4 API is dreadful mind, I wouldn't be surprised.
GQL should be more efficient because it's not returning 95% of garbage I don't need, but having to write 5-deep queries (because of the edge indirections) by hand is way more of a pain in the ass than performing two GET requests with a few parameters munged in the URLs. And then I still have to go and retrieve the information 5-deep in the resulting document.
Pagination is also awkward, because now you probably want multiple different queries (and thus multiple different resulting documents) so that your 2+ fetches don't retrieve unpaginated information you got the first time around. And it gets worse when nesting comes in.
I don't think graphql is generally a great experience when you consume it either.
- searchableguy 5y ago> Pagination is also awkward, because now you probably want multiple different queries (and thus multiple different resulting documents) so that your 2+ fetches don't retrieve unpaginated information you got the first time around. And it gets worse when nesting comes in. You don't need to write a different graphql query, use variables. Good graphql APIs will expose a start and limit field for Pagination.
- masklinn 5y agoI think you misunderstood the issue. Of course you will use variables for the pagination itself, the issue is that your head of line query will be grabbing other fields than the paginated one. You don't want to repeat these fetches in the followup queries, they're redundant, and assuming the API is rate-limited they will decrease your query budget for no value. That counts double if you're fetching multiple paginated fields (which also adds to the awkwardness).
- searchableguy 5y agoI think I got what you are saying now. If you want to get paginated children nodes, then the root will be fetched again which is a problem.
- masklinn 5y agoIndeed. It may not be a huge problem depending on how much data you need, but there are lots of cases where you'd really rather avoid refetching the rest of the root. TBF you could also deal with it using fragments I think, but still, not great.
- obi1kenobi 5y agoAgreed — consider what happens when you have a node(start: Int, limit: Int) inside or alongside another such node with start and limit. Your pagination is now two-dimensional, with each node's start/limit as points on its own axis. Now add a third node to the query. Now you have three-dimensional pagination. This quickly goes off the rails. Try writing a generic N-dimensional paginator for such a query to see why it's difficult. Even designing a sensible and reasonably flexible API for one is a headache.
- PaulHoule 5y agoPagination is a bear. Most of the simple ways of doing it with SQL are problematic. In these docs https://docs.spring.io/spring-batch/docs/current/reference/html/index.html https://docs.spring.io/spring-batch/docs/current/reference/h... there is some discussion of the problems and some answers that go back to the mainframe era.
- marcosdumay 5y agoThe server side of pagination is really complex if you want to make sure all the results are returned exactly once. If that's your case, consider not paginating at all. But very often, a result missing or duplicated in a few queries isn't a showstopper. On that case, pagination is very simple.
- PaulHoule 5y agoSpring Batch covers the cases where you have to get the right answer! That is you are "full scanning" and making a report or doing something like a reconciliation process in a financial institution, it is not like some image boards where there is a link to the 1781th page of images but it spends forever loading it if you click on it.
- obi1kenobi 5y ago100% agree that pagination is extremely awkward, especially with nesting. Between the pagination problem and the "oops I asked for too much data and blew up the server" problem, I think it's more work than one might think to run a GraphQL API. For my own work, I took things in a different direction: I made a query language that parses as legal GraphQL using a vanilla parser, but has directives like `@filter, @recurse, @optional` etc. Instead of returning a giant fully-nested result, it flattens results and emits them row-by-row like a SQL database. This means the query evaluation can be lazy and incremental — if you write a query that has a billion results but only load 20 of them, then only 20 rows' worth of work happens. My company has been using this in production for 6 years now across everything from TB-scale SQL clusters with X00,000 tables/views, to querying our own codebase, configuration, and deployment information to find and prevent bugs. I gave a 10min talk at a conference about this recently, if you'd like to learn more: https://www.hytradboi.com/2022/how-to-query-almost-everything https://www.hytradboi.com/2022/how-to-query-almost-everythin... Project GitHub: https://github.com/obi1kenobi/trustfall https://github.com/obi1kenobi/trustfall
- brasic 5y agoI work at GitHub and would love to hear more. Can you describe some of the data interactions that you find more convenient with the v3 API?
- sieabahlpark 5y agoEverything is easier to use with rest because it's so simple it works with curl trivially.
- Beltalowda 5y agoNot just cURL; most of the time I want something from the GitHub API it's something fairly simple; using REST from Python, Go, Ruby, $preferred_language is easier than using GraphQL, too. I'm sure there are libraries out there, but hard to beat a simple "fetch me data from that URL yo".
- brasic 5y agoGraphQL uses HTTP like the REST API and speaks JSON. There's no need for a library if you're comfortable sending a POST request. It seems to me like the main friction that you and others are getting at is that GraphQL is more work to use than REST because you have to write a query. That's a fair point! Perhaps we could publish "canned" queries that are the equivalent of the most commonly used REST endpoints, or make them available for use in the API with a special param.
- Beltalowda 5y agoYes, you need to write a query; and it's also not at all that obvious how to write a query. Let's say you want to list all repos belonging to a user or organisation, a fairly simple and common operation. I found [1] in about 30 seconds. I've been trying to do the same with GraphQL for five minutes now using the docs and GraphQL Explorer, and thus far haven't managed to get the same result. I worked a bit with GraphQL in the past, but never all that much. Now, I'm sure I could figure it out of I sit down, read the basics of GraphQL, familiarize myself with GitHub's GraphQL schema, etc. But ... it's all a lot of effort and complex vs. the REST API; even with a solid foundation in GraphQL there's still lots more parts. GraphQL is kind of like giving people a schema to an SQL database and telling them that's an "API"; it kind of is, but also isn't really. There's a reason almost all applications have some sort of database layer (API!) to interact with the database, rather than just writing queries on the fly whenever needed. [1]: https://docs.github.com/en/rest/repos/repos https://docs.github.com/en/rest/repos/repos
- dustymcp 5y agoHaving consumed both and recently rewriting a lib to graphql i know enough to not wanting to roll my own..
- atom_arranger 5y ago> but having to write 5-deep queries (because of the edge indirections) by hand is way more of a pain in the ass than performing two GET requests with a few parameters munged in the URLs. And then I still have to go and retrieve the information 5-deep in the resulting document. I usually write my queries in GraphiQL (check some boxes) and then paste them into the app after I have them working right.
- camgunz 5y agoI think GraphQL is best understood as an incomplete ORM that you have to complete yourself on the backend. If GraphQL generated SQL (given some tooling or what have you) pretty much all the problems are solved. Indeed backend-as-a-service products like Hasura or Postgraphile are this missing piece. I guess we're uncomfortable with SQL over the wire or open-to-the-world databases, but we shouldn't be. Or maybe TLDR "dear next generation of engineers: SQL is actually pretty good".
- discreteevent 5y agoSQL is excellent but exposing your database is not. The inventors of graphql specifically said that they don't think that it is a good idea to do so. They never intended it for that.
- camgunz 5y ago> SQL is excellent but exposing your database is not. That was definitely true before Postgres got row security (admittedly in 2016, after GraphQL was released in 2015), but these days there's really no need to run an entire app server in front of your database just to implement permissions.