TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why use GraphQL, good and bad reasons

186 pointsby vvoyerover 6 years ago

24 comments

kodablahover 6 years ago
Con: Unpredictable code paths (at least in complex use cases).<p>I&#x27;ve seen so many times GraphQL implementations or ad-hoc equivalents with user supplied property and filter requests, that regret giving the caller so much flexibility. IME, flexibility is a bad thing because in the API world, often once you cross a feature bridge, there&#x27;s no going back. I say be very restrictive in your API for many reasons. And for that UI use case, I disagree with a complete client-side&#x2F;server-side dev separation. Unlike data APIs, backend data requests for frontend use should be tightly tailored to what is used. GraphQL is just another way to forget what you&#x27;ve exposed and also allow clients to hit never before seen code paths to your backend. There are security, bloat, and maintenance concerns...keep the UI backend thin and light and inflexible and strict and limited yet agile and volatile and you&#x27;ll be so happy you did a couple years down the road.
评论 #17837011 未加载
评论 #17835705 未加载
评论 #17836244 未加载
评论 #17836783 未加载
评论 #17837757 未加载
评论 #17840009 未加载
hn_throwaway_99over 6 years ago
This is kind of touched on by other comments here, but after using GraphQL heavily on a bunch of different projects for both native apps and web UI front ends, one of the biggest benefits I&#x27;ve seen is how it enables the individual teams (front end and back end) to work faster, more efficiently, and more independently.<p>Our dev process for using GraphQL:<p>1. Product and design come up with screen designs and workflows.<p>2. Importantly, the <i>front end teams</i> then take a first stab at writing the GraphQL type contracts, fully doc&#x27;ed (we use a Node backend, so it&#x27;s easy for the front end folks, even native app devs, to know enough JS to write these type strings). They then confer with backend folks on the contract to get agreement, and front end folks write mock endpoints for these contracts. This allows the front end teams to get off to the races early with a working (albeit mocked out) backend. Since the GraphQL type contracts are optimized to closely match the front end screens, it makes the front ends <i>much</i> simpler. With native apps it also means there are a lot more things we can fix with just a server change, not requiring an app store release.<p>3. Backend folks then start implementing the GraphQL resolvers, which in our architecture is mainly orchestrating microservices. The great thing about GraphQL here is that it essentially serves as a &quot;decoupling layer&quot;, giving the backend folks a lot more freedom to change and switch up the microservices as long as the GraphQL contract is still respected.<p>4. Once the GraphQL resolvers are done, we switch out the mock resolvers. Usually there are a couple of edge cases or other bugs to fix, but for the most part we&#x27;ve seen very little disconnect.
评论 #17836516 未加载
评论 #17835571 未加载
dustingetzover 6 years ago
The backend scaling&#x2F;complexity problems originate in the database, its kind of cute the way they put it: &quot;Making the graph-oriented way of getting data fit over an SQL database can be tricky.&quot; Tricky vastly understates this: we are talking about ORM, the &quot;vietnam of computer science&quot;<p>Clojure ecosystem has an immutable database, Datomic, which is designed for functional programming and fully solves the impedance mismatch. Datomic &quot;Pull queries&quot; is essentially GraphQL – and even predates GraphQL by a year!<p>Unlike GraphQL, Datomic is also a real database, competitive with SQL and can express relational filters and joins. Datomic is designed for the read-heavy data modeling loads that, today, SQL (and mongo, etc) is used for in anger. <a href="https:&#x2F;&#x2F;www.datomic.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.datomic.com&#x2F;</a>
评论 #17835355 未加载
评论 #17834906 未加载
评论 #17835471 未加载
theptipover 6 years ago
I&#x27;ve still not seen tooling in the Python ecosystem to make a GraphQL API actually safe to expose to the internet -- without query complexity policing, a malicious client can construct queries that will take an effectively infinite amount of time to complete, and take out your DB connection.<p>Github handles this problem: <a href="https:&#x2F;&#x2F;developer.github.com&#x2F;v4&#x2F;guides&#x2F;resource-limitations&#x2F;" rel="nofollow">https:&#x2F;&#x2F;developer.github.com&#x2F;v4&#x2F;guides&#x2F;resource-limitations&#x2F;</a><p>Is this something that&#x27;s generally solved in other languages? (I&#x27;ve seen a few plugins on NPM that tackle the problem). Or is this just not something that implementors are worrying about?
voidrover 6 years ago
Most GraphQL presentations I have seen tend to construct the following strawman scenario:<p>- we have a REST API that forces the client to make too many requests - it&#x27;s impossible to fix the REST API for some reason - the app is slow because of the multiple REST API calls<p>The followup:<p>- we bring in GraphQL and everything becomes super fast and efficient - the people who couldn&#x27;t provide an efficient REST API, can all the sudden provide a GraphQL interface - the cost of implementing and maintaining GraphQL is usually glossed over<p>The reality is that GraphQL has a lot of drawbacks that are overlooked:<p>- it might be cheaper to fix the REST API than to implement GraphQL - it&#x27;s one extra service or module(if you are lucky) on your backend to look after - protecting the database from bad queries becomes an order of magnitude harder - you will have to maintain an additional GraphQL schema - the client side tooling for GraphQL is far from simple<p>Depending on your needs, it might still be worth it, I would just wish that GraphQL presentations would be more honest about these.
atom_arrangerover 6 years ago
Adding to the pros:<p>Self Documenting - GraphQL documents the shape of responses properly. It&#x27;s like Swagger if the spec always actually matched the implementation. This is a big win for everyone. Backend doesn&#x27;t have to think about updating separate documentation, frontend always has an up to date and accurate spec.
iamleppertover 6 years ago
If you go down the GraphQL path be aware you are trading the simplicity, flexibility and universality of HTTP, which you can debug via cURL, to a custom protocol and fat client owned by Facebook. It isn’t even an open standard. The last time Facebook tried to make HTML better we got FBML, remember that?<p>Be wary of tech that promises to solve all your problems that you yourself don’t understand and haven’t solved. You’re going to end up with at best another set of problems.
评论 #17838348 未加载
iEchoicover 6 years ago
&gt; A GraphQL API (server) implementation, out of the box, will have better performance than a standard REST API - for the clients. Since resolvers are called in parallel, data will load faster.<p>What does this mean? Are these theoretical REST endpoints fetching information serially, or something?<p>Almost all of our REST endpoints fetch all of their information in a single hand-optimized SQL query. How is GraphQL going to run faster than that?
评论 #17837280 未加载
评论 #17837291 未加载
评论 #17837456 未加载
pranayairanover 6 years ago
Coming from Mobile developers experience :<p>- Graphql does allow you to specify data you need and make the user experience better but this is only true in theory. Since in graphql it is so easy to ask any data there are high chances of your queries not optimized and you end up doing a complex operation spanning multiple domains because you can do it. In REST since domains are tightly defined chances of non-optimized request are less.<p>- Another major con with GraphQL on mobile is there are no alternatives than Apollo client yet. This ties you to 1 solution for your entire application.<p>- There are companies that tried to enable Querying over rest. Though it is not as flexible as GraphQL.
评论 #17836314 未加载
评论 #17836067 未加载
Vinnlover 6 years ago
I don&#x27;t see why &quot;rich UI&#x2F;UX-based applications&quot; is listed as &quot;mobile-first&quot;. Sure, GraphQL is probably great for highly dynamic client applications, but why would that be limited to mobile?<p>As far as I can tell, GraphQL primarily allows you to trade client flexibility for back-end complexity. If you&#x27;re willing to take the additional complexity on the back-end, GraphQL allows you API clients to iterate far quicker, and removes (or at least lessens) the dependency of the client on the team maintaining the back-end. If that&#x27;s not worth it to you, don&#x27;t use GraphQL.
评论 #17835319 未加载
评论 #17835736 未加载
评论 #17835250 未加载
aaronblohowiakover 6 years ago
One huge benefit is that the client controls the response shape and the same server will power multiple different response schemes without requiring any changes. Very nice for supporting N types of clients.
guiriduroover 6 years ago
Correct me if I&#x27;m wrong, but having read around the topic of GraphQL with a slowly-changing, largely static catalogue type appication in mind (ideal fit for CDN in front of REST); I remember a few horror stories around GraphQL not being CDN-friendly.<p>Perhaps if you have a dynamic or real-time data-lake or messaging-style app with quickly-stale data that would need to be talking to regional server clusters anyway, then GraphQL has benefits on top for schema independence etc. But I wonder if its CDN caching story has improved (not just client-side as mentioned.)
评论 #17835428 未加载
评论 #17835297 未加载
评论 #17835213 未加载
dustingetzover 6 years ago
OCFX, it appears you&#x27;ve been shadowbanned. Your question is very good so reposting it here:<p>&gt; Does anyone know how GraphQL manages (or if it even can) to sort and filter across microservices? It seems impossible to me to do from any client. If you have a list view that is made up of data from microservice a, b, and c and you try to sort on a column from microservice b, how does microservice b know how to sort then data when there are additional constraints applied to data on other microservices such as a filter applied to microservice a. Does that make sense? Basically I feel very frustrated when it comes to sorting and filtering across microservices, some people at work think that GraphQL will solve this and I have found absolutely nothing to support the claim that it would help us with this. Thoughts?
评论 #17835598 未加载
评论 #17838249 未加载
headcanonover 6 years ago
One thing I&#x27;d like to add, if your primary data store resides in a document-oriented DB like Mongo or Dynamo, GraphQL provides that missing &quot;relational&quot; piece, and allows you to create a strong schema without having to manually do &quot;joins&quot; in application code. I realize attempting to &quot;relationalize&quot; a document store isn&#x27;t how you were supposed to use it, when I started at my current company thats what they had going on. GraphQL was essential for improving the sanity of how we grab data from dynamo, and gave us a good way to iteratively migrate over to Postgres where appropriate.
chvidover 6 years ago
Seriously they are both bad ideas (graphql and rest). Just create a remote method doing exactly what you need with a well-defined metaprotocol. It really doesn’t have to be so hard.
TheAceOfHeartsover 6 years ago
This reads like an Apollo ad.<p>I&#x27;ll start off by noting that I haven&#x27;t been keeping up as much with the latest developments within the GraphQL ecosystem so some of my comments may be outdated.<p>They ignored one of the most thorough GraphQL implementations: Sangria [0], which provides almost everything you need out of the box to implement a fairly sophisticated application. I guess that Scala isn&#x27;t very cool. I&#x27;d reluctantly agree that most of the community seems to be centered around the JS ecosystem, but I don&#x27;t think it&#x27;s fair to so easily dismiss the dozens of GraphQL implementations out there. Perhaps I&#x27;m wrong about this, but based on the author&#x27;s bio it sounds like they&#x27;re most experienced with JS and Ruby, which means that they&#x27;re probably heavily biased towards those two languages. I don&#x27;t think they&#x27;ve seriously evaluated each library extensively and they should be transparent about it if that&#x27;s the case. I&#x27;ve used GraphQL with Elixir, Node, and Ruby, but took a lot of inspiration from Sangria&#x27;s docs when working on my apps.<p>I don&#x27;t know if it was meant as a criticism, but I actually think that the declarative syntax used with Elixir and Ruby is quite nice. The examples provided for the reduced &quot;Developer Experience&quot; are rather weak in my view. I think the author might just be most comfortable with JS.<p>&gt; Secondly, as said in the second point, a GraphQL API server needs optimisations and maintenance.<p>&gt; Making the graph-oriented way of getting data fit over an SQL database can be tricky.<p>IMO, this is severely understating the complexity. Depending on the type of application, you should probably be prepared to have at least one engineer dedicated full-time to maintaining your GraphQL server.<p>It&#x27;s a lot easier to write a secure REST API with good performance than it is to achieve the same thing with GraphQL. The author doesn&#x27;t even mention anything about the huge headache involved with protecting against malicious queries.<p>I immediately fell in love with the idea of GraphQL when I first heard about it, but as I started to use it I found it wasn&#x27;t some magical solution. You&#x27;ll probably end up having to figure out a lot of stuff on your own since the technology is so young, so be prepared to invest a lot of time in it. It depends heavily on your use-case and your team&#x27;s collective experience, but I&#x27;d probably lean towards avoiding GraphQL within a small team.<p>If race conditions aren&#x27;t a concern, you can wrap a REST API with a small GraphQL server. The inverse is also possible.<p>There&#x27;s no mention of file uploads. Although many GraphQL libraries include some form of file uploading capability, I&#x27;d suggest against using that and just creating separate endpoints for each upload type. Having a separate endpoint makes it way easier to place reasonable limits on input size, as well as rate-limiting those actions adequately. You can also handle streaming uploads, which I don&#x27;t think most GraphQL libraries can handle; if I recall correctly the Node GraphQL server parses the whole body before executing any resolver.<p>[0] <a href="https:&#x2F;&#x2F;sangria-graphql.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;sangria-graphql.org&#x2F;</a>
asciimoover 6 years ago
Episode 27 of the Syntax podcast gives a good overview of GraphQL and its ecosystem. Demystified a lot for me. <a href="https:&#x2F;&#x2F;syntax.fm&#x2F;show&#x2F;027&#x2F;graphql-here-is-what-you-need-to-know" rel="nofollow">https:&#x2F;&#x2F;syntax.fm&#x2F;show&#x2F;027&#x2F;graphql-here-is-what-you-need-to-...</a>
danpalmerover 6 years ago
This is a great summary of the reasons why I initially dismissed GraphQL, and why I&#x27;m now a fan - having gone through a process of evaluating it against REST for a production API for a mobile app.<p>Great post.
makkesk8over 6 years ago
Has anyone used odata? Do you prefer odata over graphql?
评论 #17835896 未加载
Justsignedupover 6 years ago
has anyone used JSON API? How does it compare to graphql? Did you find JSON API was better until you hit a certain size?
评论 #17835176 未加载
评论 #17835326 未加载
评论 #17837548 未加载
评论 #17835327 未加载
orefaloover 6 years ago
It&#x27;s pretty simple... do access the DB (assuming it&#x27;s SQL) do you prefer SQL or PLSQL.
ravitationover 6 years ago
Good and bad reasons to use something are not the same thing as pros and cons...
krnover 6 years ago
Why would one choose GraphQL over gRPC for a native iOS &#x2F; Android app?
评论 #17835191 未加载
ocfxover 6 years ago
Does anyone know how GraphQL manages (or if it even can) to sort and filter across microservices? It seems impossible to me to do from any client. If you have a list view that is made up of data from microservice a, b, and c and you try to sort on a column from microservice b, how does microservice b know how to sort then data when there are additional constraints applied to data on other microservices such as a filter applied to microservice a. Does that make sense?<p>Basically I feel very frustrated when it comes to sorting and filtering across microservices, some people at work think that GraphQL will solve this and I have found absolutely nothing to support the claim that it would help us with this. Thoughts?
评论 #17837652 未加载
评论 #17838342 未加载