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.

Ask HN: Were you happy moving your API from REST to GraphQL?

301 pointsby glenscott1almost 7 years ago

49 comments

Androideralmost 7 years ago
As a consumer of APIs I vastly prefer REST APIs.<p>In my opinion, GraphQL moves too much of the burden to the user of the API. It makes most sense if the data is highly dynamic, you have a mobile app and every call is expensive, or (and this seems more common) the backend and frontend teams don&#x27;t like to talk to each other. As a user, I just want to GET &#x2F;foo, with a good old API token I pasted from your dev docs, and move on to the next thing. I don&#x27;t want to spend time figuring out your database schema. Or perhaps I&#x27;ve just yet to see single good public GraphQL API. I just recently had look at the Github GraphQL API and it&#x27;s non-existent docs (no, I don&#x27;t want introspect your data models at runtime), noped the hell out of that, and got the REST integration for the bit I needed done in an hour.
评论 #17568551 未加载
评论 #17567628 未加载
评论 #17567559 未加载
评论 #17568005 未加载
评论 #17567880 未加载
评论 #17568639 未加载
评论 #17568303 未加载
ilovecachingalmost 7 years ago
Absolutely. Before GraphQL we were making a monumental effort to build a REST API. After deliberating on exactly what REST was and how we’d represent a few red haired resources, we were spending a lot of client time fetching deep trees through resource links. When we moved to GraphQL it solved a lot of the administrative and philosophical headaches and considerably reduced the number of connections, wasted data, and made our client code so much simpler through easily grokked queries. Highly recommmend GraphQL to anyone.
评论 #17566465 未加载
评论 #17566923 未加载
评论 #17566665 未加载
评论 #17567935 未加载
评论 #17566821 未加载
评论 #17568167 未加载
heavenlyhashalmost 7 years ago
Yes. (Mostly.)<p>REST semantics are a distraction. The best possible outcome of REST is when developers are encouraged to consider the concept of &quot;idempotency&quot; when they stumble upon the technical definition of the &quot;PUT&quot; verb. Everything else is line noise.<p>GraphQL has a schema with types. It makes it very straightforward and approachable for all developers to reason about what an API should deliver up-front, and also easy to reason about what is and is not a breaking change. Automatic validation of queries against the schema also saves massive amounts of time in writing validation logic.<p>There are still things that could be better with GraphQL. The query language is... interesting. The whole thing is still very client-server asymmetric -- look at a client query syntax versus the schema syntax you&#x27;ll use on the server side for three seconds and you&#x27;ll immediately and viscerally know what I mean -- and that strikes me as disappointing in this age. It&#x27;s still very easy for developers to fall into mental quicksand which causes them to make many individual requests even when GraphQL <i>would</i> let them batch things up into one. And so on.<p>But overall: yes, working on a GraphQL stack is an awesome experience compared to going it alone with REST and JSON and crossed fingers.
评论 #17566678 未加载
评论 #17567941 未加载
haneyalmost 7 years ago
Mostly, NOTE: I&#x27;m using python&#x2F;django&#x2F;graphene server side and apollo client side.<p>I <i>love</i> how flexible it is for client developers and because the great client side libraries it helps to eliminate a ton of boiler plate code on the client side.<p>My biggest complaint has been &quot;lost&quot; exceptions and caching.<p>Because it&#x27;s possible for an exception to be thrown server side on one field while the other ones succeed I&#x27;ve been plagued with hard to monitor&#x2F;find errors. I ended up writing a shim to parse the response in an attempt to get more insight into #errors &#x2F; fields (this has also been really helpful for monitoring slow queries in new relic since all requests go to the same endpoint which breaks a ton of APM monitoring).<p>My other issue has been around caching, in apollo there are ways to say &quot;don&#x27;t use the cache for this request&quot;, but it&#x27;s not to give an object a cache ttl. My app allows users to search for events that are happening near them right now, and I&#x27;ve run into several issues where apollo decided that an event from yesterday should be added to a result. It happened frequently enough even with queries that included times as an argument that I ended up basically implementing a &quot;middleware&quot; between what apollo gives back and the component, which felt really ugly.
评论 #17566533 未加载
评论 #17567777 未加载
评论 #17566717 未加载
评论 #17566817 未加载
评论 #17568840 未加载
评论 #17566381 未加载
评论 #17567450 未加载
ergothusalmost 7 years ago
My company has been flirting with graphql.<p>As a frontend dev, I had a positive experience with one service because the backend was far more willing to add new query options. The much publicized &quot;only get what you ask for&quot; part was largely irrelevant.<p>I am, however, unsettled at the prospect is losing all the built in network and browser caching for idempotent calls (mostly I&#x27;m unsettled because no one else seems to seriously consider the issue - it may end up too small to matter, but I dont trust that anyone else here has honestly evaluated it).<p>Another poster mentioned the issue with partial errors, which sounds like something else that will not get the upfront attention it deserves, while not being an immediate dealbreaker. Add in to that how to manage deprecation of particular query statements as they can no longer be distinguished as distinct endpoints.<p>My other concern is how much magic frontend libraries provide. This magic looks great if your app is nothing more than input&#x2F;output over CRUD calls, but sounds very brittle if your app has client side logic (and while perhaps a webapp should ideally avoid that, other services can also be clients.)<p>So far I have concerns but not concrete problems, I just worry that we wont be able to confirm the severity until we&#x27;ve already invested and committed, particularly when our initial adopters are so enthusiastic. At the same time I don&#x27;t want to be the guy unwilling to change and adopt new things.
评论 #17566405 未加载
ulkeshalmost 7 years ago
We decided against it. We’re in a java backend and GraphQL in Java with ORM is considerably problematic when trying to create efficient resolvers. We simply ran into one hurdle after another and we were finding ourselves in diminishing returns.<p>The concept is great, and if you write custom SQL queries for each resolver (if necessary), properly caching things that can be cached, and use the first class citizen programming language (JavaScript), then it seems GraphQL works wonderfully.<p>Trying to fit it into an existing ORM paradigm with respect to complex sub-collections, lazy loading, and efficient database querying, it just didn’t work out for us.
评论 #17566977 未加载
评论 #17566879 未加载
评论 #17566986 未加载
valwalmost 7 years ago
We migrated most of our backend (written in Clojure) from REST to GraphQL (actually a homemade alternative to GraphQL, but not relevant to this discussion).<p>It went well, it greatly simplified both our backend and frontend code. The backend code got simpler and more stable because it no longer had to deal with &quot;data packaging&quot;. The frontend code became more transparent, because you can now easily read what data gets exchanged, and more decoupled, because different components can independently require the data they care about. One of the biggest benefits has been the degree of independence to evolve both the client and server.<p>We haven&#x27;t had the performance issues some people have mentioned (N+1 query etc.), because of the server-side design of our homemade GraphQL engine - in which data resolvers are batching and asynchronous by default, unlike most backend libs which approach this problem more naively. Will open-source that soon.<p>The biggest limitations I see to GraphQL are:<p>- it doesn&#x27;t really have a story for caching. I have some ideas for addressing that, but it hasn&#x27;t been a problem for us really.<p>- it repeated the SQL mistake of exposing a query language based on text, not data structures. Now we have to write queries as templates instead of assembling them programmatically. This hurts both application developers and library authors.<p>- it doesn&#x27;t really have a story for structured writes.
评论 #17568940 未加载
throwaway2016aalmost 7 years ago
I tend to write publicly facing APIs so this conversation is colored a little by that. An internal API or Microservice is a different story.<p>I don&#x27;t think it is either of. I use both. In the same API. The two are largely compatible.<p>All REST APIs can be modeled in RPC style APIs and that&#x27;s no different with GraphQL.<p>I&#x27;ve done APIs where I have a GraphQL facade in front of REST and REST Facades infront of GraphQL by having all my REST endpoints be two lines<p>1. Graph QL query<p>2. Format result as REST<p>That first like maps to a graphQL query and the second one can be standardized for all your REST endpoints.<p>I tend to like REST in-front of GraphQL better since it allows for some performance optimizations when you know ahead of time all the data you need to grab.<p>And since GraphQL can be mapped to classes you could also just skip the GraphQL query compile and use the classes directly from your REST with only a few more lines of code.<p>Overall I like GraphQL a lot because it allows the frontend to make less round trips to the server and makes it easier to exclude data you don&#x27;t want (which helps when data is large). Json:API tries to solve some of this with includes, related, and fields but it doesn&#x27;t quite allow as much expressiveness as GraphQL.
评论 #17566047 未加载
OldSchoolJohnnyalmost 7 years ago
You&#x27;re going to get responses from people who have invested a considerable amount of time in something they already had plans for (a &quot;sunk cost&quot;) so I&#x27;m not sure you will get the sort of information you are after here.
评论 #17567427 未加载
评论 #17566452 未加载
评论 #17567486 未加载
BerislavLopacalmost 7 years ago
These are taken from some of the other comments in this thread:<p><pre><code> * As a consumer of APIs I vastly prefer REST APIs. * Highly recommend GraphQL to anyone. * I *love* how flexible it is for client developers. * As a manager&#x2F;business owner, I like GraphQL. * How I _wish_ I could nope the hell out of our GraphQL dependency * Unnecessary complexity over simple rest calls with no benefits. * REST semantics are a distraction * my experience is just ok. </code></pre> What I see here is many different reactions from different people, presumably with different experiences and use cases on their hands. And that&#x27;s perfectly OK -- REST, GraphQL, XML-RPC, heck even SOAP are just tools, and use whichever works best for your particular situation.<p>Just because it worked for me doesn&#x27;t mean it will work great for everyone else; and if it sucks for me doesn&#x27;t mean it won&#x27;t be a life-saver for someone else. Those are just tools; use them as you find fit.
t_fatusalmost 7 years ago
I&#x27;d like to add that correctly designed resolvers allow you: - to control very easily who can fetch what where it&#x27;s fetched (permissions) - to fetch nested data when you need it without writing serializers - to help your frontend team find what they are looking for without asking the backend team everytime - mutations are a huge plus when it comes to standardization of your API too<p>FYI we&#x27;re using it in production over a django backend (which comes with some drawbacks, since subscriptions == pushed updates are not perfectly implemented) with our react&#x2F;apollo apps (web and native) and in my opinion the overhead lies surprisingly more in the frontend side (writing data connectors is longer, but way more explicit, than using rest queries returning json)than on the backend (where you just declare resolvers, a thing you don&#x27;t even need to do in nodejs) and handle permissions.
评论 #17567767 未加载
评论 #17567037 未加载
SingAlongalmost 7 years ago
GraphQL is great for the frontend, but moving to GraphQL involves both people and tech issues. Common mistakes made when using new technologies are made all over again.<p>* Watch out for bad implementation of the GraphQL API (this will definitely result in bad performance).<p>* Design the GraphQL schema that you want the user to see&#x2F;perceive. Not every object or field in your database needs to be exposed via the API the way it is.<p>My workplace is currently moving a huge monolith into a bunch of manageable components. Each of these components has its own GraphQL endpoint. Using schema-stitching, these are being stitched together into one endpoint for API users.<p>As a result of our codebase, we&#x27;ve tried GraphQL in:<p>* Ruby (graphql-ruby) - WATCHOUT Relay arguments for connection fields are not exposed to the library user. So basically you have to implement your own Relay-compliant stuff if you need access to the pagination arguments from Relay. Also, documentation is broken.<p>* Python (graphene) - We&#x27;ve had no issues so far. We worked around it.<p>* Node.js (Apollo GraphQL) - OH MY BUTTERFLIES. So far, this is the ONLY library I have come across that is polished and has plenty of documentation.<p>* Elixir (Absinthe) - My coworker worked on this part. He did not complain. So I&#x27;m assuming he had no issues.<p>The &quot;Learn * in a day&quot; joke applies to GraphQL. As simple as GraphQL looks for the client-side, it is beast of a job to build a GraphQL backend that is optimized for production.<p>Servers-side implementation of GraphQL is not very well documented apart from hello-worldly examples. Most of the knowledge found online is about client-side usage.<p>Due to poor documentation&#x2F;examples provided, ramping up people with GraphQL is hard. Most first iterations I&#x27;ve had to review were slower than our REST APIs because of unoptimized code. Sitting down for a few minutes solves that problem.<p>To ramp up people at work place, I ended up having to do this:<p>* Ask people to use the GitHub v4 API to checkout GraphQL.<p>* Make them build a GraphQL server for a blog app.<p>* Dive straight into whatever feature&#x2F;API they would build.<p>* Review their work a few dozen times and show them optimization tricks.<p>My most valuable lesson: When in doubt, dig into the source of these libraries.
jaequeryalmost 7 years ago
my experience is just ok. as someone here puts it, great for frontend devs but bad for backend devs.<p>if you have db schemas on the backend if using orm, get ready to duplicate them again for graphql.<p>and on the frontend, get prepared to write out every songle fields you need from the backend. i can imagine it may be brutal for those who have a lot of changes in their schemas.<p>my conclusion is that, since im a fullstack who does both frontend and backend, i feel myself getting a bit more fatigued than when i was doing rest style api. i find myself wanting rest time to time, esp at times i dont feel like writing out all the fields i need back that i cant remember off top of my head.
评论 #17566345 未加载
评论 #17567498 未加载
syvexalmost 7 years ago
We&#x27;ve just started to dabble in GraphQL, and like many others we&#x27;ve seen mixed results.<p>On the upside, we can construct complex queries than eliminate many consecutive RPCs that you&#x27;d end up with in a traditional REST API. At scale this should work wonderfully, greatly reducing the client&#x2F;server latency for our realtime app.<p>On the downside, the tooling is still far behind. This is somewhat due to GraphQL being a younger technology so you have to give it some time. OTOH, I feel like you can get things off the ground with REST more quickly. Problems with GraphQL tend to be harder to reconcile due to the debug tooling handicap.<p>Some of our engineers take a little time ramping up to GraphQL due to its complex nature. This is probably a good thing in the long run though, since it stresses the importance of keeping RPCs to a minimum and eliminates having to sync or batch consecutive RPCs.<p>Overall I still think it&#x27;s a win. The tooling should improve over time, and hopefully it will be a first-class citizen in IDEs and libraries soon. Until then, you&#x27;ve got to be prepared to muscle though it.
schrocknalmost 7 years ago
Nick Schrock here, one of the GraphQL co-creators. I agree with a lot of the criticism in terms of the difficulty of implementing GraphQL backends. I think there&#x27;s a big opportunity for folks to build vertically integrated toolkits that deal with N+1 issues, integrate DataLoader natively and so forth. Good versions of these would deal with a lot of issues described here in greenfield GraphQL backends. I talked about this at the GraphQL Europe keynote last month (<a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=zMa8rfXI6MM" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=zMa8rfXI6MM</a>).<p>Current greenfield implements are typically stacked on ORMs like Django and RoR, and the impedance mismatch is real. Personally I abide by the dictum that ORMS are &quot;Vietnam of computer programming&quot; and should be avoided at all costs for anything that will grow beyond a small app. GraphQL was not originally implemented on top of an ORM, but instead an object model built on key-value + edge store internal to Facebook.<p>In terms of other criticisms in this thread:<p>1) Exceptions: The default behavior in graphql-js (mimicked in other language implementations) of swallowing native exceptions by default was probably a mistake in hindsight. Whenever I&#x27;ve played with GraphQL using different toolsets the first thing I change is to add a wrapper function which checks for errors and then rethrows the initial exception that caused the GraphQL error for use in testing and CI&#x2F;CD contexts.<p>2. Caching: Personally I&#x27;ve always been confused about the concern with leveraging HTTP-level caching. While a clever hack, with any real app with any sort of even mildly dynamic behavior you don&#x27;t want to do this. Staleness will be interpreted, rightly, as bugs by your users. If you want to replicate the behavior the most straightforward way would be to use persisted queries (described here <a href="https:&#x2F;&#x2F;blog.apollographql.com&#x2F;persisted-graphql-queries-with-apollo-client-119fd7e6bba5" rel="nofollow">https:&#x2F;&#x2F;blog.apollographql.com&#x2F;persisted-graphql-queries-wit...</a>) combined with HTTP GETs. With persisted queries you can encode the entire request in the query string, which should get you the HTTP-level caching you want.<p>3. Docs: Quite confused about this one. While particular implementations of GraphQL can be problematic the documentation of the core language (which I am not responsible for) is superb. See <a href="http:&#x2F;&#x2F;graphql.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;graphql.org&#x2F;</a> and <a href="https:&#x2F;&#x2F;www.howtographql.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.howtographql.com&#x2F;</a>.
评论 #17569039 未加载
IBCNUalmost 7 years ago
Not at all (we rolled our own back end). The added complexity of building queries to join our API ended up creating such a quagmire of SQL that any dev coming in will basically have to learn our own custom ORM.
评论 #17566538 未加载
013aalmost 7 years ago
It makes many things easier and many things harder. The lack of really good backend libraries&#x2F;frameworks outside of NodeJS is the most concerning thing.<p>Also; debugging and monitoring GraphQL APIs <i>sucks</i>. Considerations:<p>- Any subfield of a query can throw an error, but the rest of the fields can succeed, because GraphQL frameworks are allowed to run each field resolver asynchronously.<p>- Because of this, any GraphQL query is capable of returning multiple errors.<p>- Rate limiting is exceedingly difficult due to nested resolvers. I&#x27;ve seen solutions which involve annotating your schemas with &quot;cost&quot; numbers, and only allowing each query to run up to a maximum &quot;cost&quot; before failing by dynamically adding the costs of each field they request. Traditional rate limiting doesn&#x27;t work.<p>- Traditional APM platforms also don&#x27;t work. Prepare to adopt Apollo Engine and pay them $600&#x2F;month on top of the money you&#x27;re already paying New Relic or Datadog.
评论 #17567338 未加载
xentroniumalmost 7 years ago
Our front end engineers were extremely happy. Me personally, as a backend engineer, not as much, but it isn&#x27;t too bad.<p>There are some quirks (error handling), performance issues (e.g. fixing n+1 queries) and DOS concerns, but again, it isn&#x27;t all that bad.<p>(we&#x27;re using rails&#x2F;graphql-ruby on backend | react&#x2F;relay on frontend)
评论 #17566430 未加载
thermodynthrwayalmost 7 years ago
I really wish everyone would just move to GRPC and be done with it.<p>GraphQL just feels too tied to the datastore on the back end to be generally useful. REST&#x2F;Swagger is hugely overcomplicated for the basic REST premise of moving objects back and forth.<p>GRPC is what REST should have been. Ship objects back and forth between multiple languages with minimum fuss.
评论 #17571637 未加载
nicwolffalmost 7 years ago
You don&#x27;t have to &quot;move&quot; to reap GraphQL&#x27;s benefits – you can just add a GraphQL layer.<p>I&#x27;m backend Systems Architect at a big publishing company, and my current primary project is an aggregating caching GraphQL proxy for our REST microservices.<p>Our front ends were making too many calls to the REST APIs, so we went overboard embedding related resources – and now they&#x27;re getting too much unneeded data back, and cache invalidation is a nightmare. Sounds familiar, probably!<p>So we&#x27;re building a GraphQL service that stitches those REST APIs together to let the caller request exactly the fields they need, from any API&#x27;s resource. By caching individual resources, rather than nested multi-resource serializations, we can invalidate easily by UUID on change events – so cache TTLs can be long – and the GraphQL API&#x27;s field resolvers can assemble complex responses with a few fast Redis MGETs, which are batched by DataLoaders.<p>This also gives us a place to centralize business logic, rather than having each front end service reimplement field formatting, resource transforms, &amp;c. Since the REST APIs remain available as the source of truth, existing services can migrate to the GraphQL proxy at their own pace, which we hope will be an easy sell since it&#x27;s so much faster.
xrdalmost 7 years ago
I&#x27;m really curious to hear from people dealing with massive JSON (or XML) responses via REST. This is where REST really falls apart with complexity that is much worse than trying to learn the complexity of GraphQL.<p>See: <a href="https:&#x2F;&#x2F;brandur.org&#x2F;graphql" rel="nofollow">https:&#x2F;&#x2F;brandur.org&#x2F;graphql</a><p>&quot;In GraphQL, every contract is explicit and observable. Providers can use something like a canonical log line to get perfect insight into the fields that are in use for every request, and use that information to make decisions around product development, API changes, and retirement.&quot;<p>You simply cannot know with a REST API what to remove if the decisions on what to return for a request are largely made by the server side team. So, you end up with massive, clunky and confusing responses. GraphQL forces the client side users to understand how to use it, and because of that you get so much more.
rwieruchalmost 7 years ago
Yes.<p>I had the chance to participate in moving the client-server architecture from REST to GraphQL when I worked for two companies as a contractor. They didn&#x27;t regret it so far. There a various advantages (and disadvantages) [0] using GraphQL.<p>But these are only the direct impacts of using GraphQL. In the case of these two applications, they had a React client application managed by a GraphQL client library. All the state management done with Redux&#x2F;MobX was reduced to a minimum, because most of the managed state was remote data from an API. Now the GraphQL client was able to take over, leaving only the local UI state for Redux&#x2F;MobX. Often it is even possible to remove these state management libraries altogether.<p>- [0] <a href="https:&#x2F;&#x2F;www.robinwieruch.de&#x2F;why-graphql-advantages-disadvantages-alternatives" rel="nofollow">https:&#x2F;&#x2F;www.robinwieruch.de&#x2F;why-graphql-advantages-disadvant...</a>
d0malmost 7 years ago
Yep, best decision. Both from a back-end experience (caching, performance, type safety) and front-end experience (flexible querying, great documentation, tracing, etc.)
jensnockertalmost 7 years ago
Yes, it&#x27;s generally quite a bit nicer. It&#x27;s not as nice as I hoped, but it&#x27;s better. The old APIs are JSONAPI-style.<p>The main disappointment is that input types are not nearly as expressive as output types.
评论 #17566029 未加载
jameslkalmost 7 years ago
GraphQL really shines for querying data, but if you do a lot of writing of data, the API starts to feel like a clumsy version of RPC. I ran into this trying to apply GraphQL to a business use case that required lots of user input. Designing mutations on both the client and the backend is pretty tedious, especially when it comes to handling the response of the mutation. For example, there&#x27;s no straight forward way to handle errors like what&#x27;s commonly done with REST using HTTP error codes.
andrewstuart2almost 7 years ago
Who says GraphQL is not RESTful, though?<p>You have resources represented as a graph and you&#x27;re asking for the state (in some representation -- probably JSON, but maybe protobuf, etc), just in a more expressive and deeper way than a simple HTTP Get with a single URL can express.<p>Nothing about REST ever said that a resource locator had to be a URL, or that a single resource can&#x27;t represent a collection of resources.<p>That&#x27;s all GraphQL does, IMO. It lets you more flexibly and expressively ask for stat of a collection of resources.
misterbowfingeralmost 7 years ago
Not someone who&#x27;s moved to GraphQL, but still curious how people do load testing and such with GraphQL APIs. Do you log which queries are made, and then plan around that?
blaster151almost 7 years ago
Is it common yet for public-facing APIs to be implemented with GraphQL? Is it feasible if you&#x27;re trying to make it accessible and easy to use for casual developers?
jonotimealmost 7 years ago
Another django&#x2F;graphene shop here. I&#x27;m really enjoying the transition. My one complaint is with deep queries. If the query asks for a very nested objects, the amount of DB fetches can become large and then you get a performance hit. With REST you generally know the performance of your queries since the schema is static. How do people solve the n + 1 issue here?
kasbahalmost 7 years ago
Currently evaluating using GraphQL. I have used it for a smaller endpoint [0]. I like the server side as I feel it lets me express the purpose of the API really well.<p>I have been using straight HTTP requests to query the GraphQL endpoint. Now, wanting to do something more complex, I am disappointed in the state of GraphQL clients. Everyone says use Apollo but it has some serious issues (e.g. caching [1]). Relay seems over-kill&#x2F;restrictive and none of the other alternatives seem complete. I feel like maybe my life will be a bit easier if I just stick with REST especially since I am proxying an exiting API.<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;monostable&#x2F;kitspace-partinfo" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;monostable&#x2F;kitspace-partinfo</a><p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;apollographql&#x2F;apollo-client&#x2F;issues&#x2F;3452" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;apollographql&#x2F;apollo-client&#x2F;issues&#x2F;3452</a>
naileralmost 7 years ago
I&#x27;m holding off until I don&#x27;t have to define types in 3 places:<p>1. TypeScript<p>2. Document database<p>3. GraphQL<p>I know there are things that do two of these. I want all three.
评论 #17566667 未加载
评论 #17567702 未加载
评论 #17566572 未加载
mej10almost 7 years ago
We have, so far, only made a GraphQL endpoint for internal use. It has been awesome for quickly finding things in a medium-complexity database schema (30 or so tables, bunch of different relationships). It has become my preferred way to quickly find things in the database.<p>That being said, there are cases where a join between ad hoc subqueries is the best way, and GraphQL doesn&#x27;t really offer a way to do that (though I don&#x27;t see why it wouldn&#x27;t be possible). E.g. arbitrarily combining two GraphQL queries that return lists where some field in one is equal to some field in another.<p>But in terms of replacing REST, where you have to do all of that anyway, it is far and away the better option (for ad hoc querying, at least).
评论 #17567529 未加载
dnscoalmost 7 years ago
No. It cold have been that Relay the JS graphql implementation we used was too heavy handed, but our team never fully grokked what was going on. It wound up introducing a bunch of friction into our workflow, and we ultimately wound up removing it.
dandigangialmost 7 years ago
I just wanted to say thanks to everyone that commented! We&#x27;ve been exploring if GraphQL was something worth trying out and it seems like it&#x27;s worthy of a trial on some of our lower impact applications. Great thread here.
bradhiltonalmost 7 years ago
Yes, our team has migrated to GraphQL and it has been great, both on the front and backend.<p>We have a Django app on the backend and have used Django REST Framework for our REST API. That was a great experience, but had some limitations. We&#x27;ve written our new GraphQL API with the help of Graphene and it has been awesome. Everything is very declarative and exploring the API schema couldn&#x27;t be easier using GraphiQL.<p>Implementing it on the frontend has been great too. Yes, you do have to specify what fields you want, but having complete control is worth the extra boilerplate. I&#x27;d recommend it heartily.
iamleppertalmost 7 years ago
I really wanted to like GraphQL but ultimately decided against it. It&#x27;s one of those things that seems great in theory but when you actually start working with it you see all the warts.<p>The client libraries are too complex, there&#x27;s too much magic going on, debugging is a pain, there&#x27;s not a lot of native support in browsers and mobile devices. I don&#x27;t want to step into the code of a client library I didn&#x27;t write to figure out some simple query issue. It&#x27;s no longer a simple matter of just an HTTP request anymore. It&#x27;s not a pragmatic choice.
DiabloD3almost 7 years ago
The problem with REST is largely the people who look at it blindly as &quot;thing that makes the CRUD go&quot; instead of as a methodology of how to effectively use HTTP verbs and designing URIs that make sense.<p>So I guess my question is, why <i>would</i> I use GraphQL over, say, the Swagger tool suite? Swagger and the OpenAPI spec defines a way of doing REST that best fits both what Roy Fielding meant for REST but also fits IDE and tool automation systems.
评论 #17566494 未加载
vinayan3almost 7 years ago
Yes exception for File uploads. There isn&#x27;t a spec and not all apollo clients yet support it.<p>Hopefully, it&#x27;ll be standardized soon.<p>For writing React Apps GraphQL is wonderful!
smt88almost 7 years ago
For a mature product, no. We closely looked at engineering time and realized we&#x27;d never make our investment back.<p>For a new product, yes (so far).
stevefan1999almost 7 years ago
Absolutely. REST APIs are passive and GraphQL APIs are the vice versa, very active and progressive in nature, GraphQL also comes with a simpler model to process real time data (subscriptions). However, it is relatively hard to scale GraphQL (especially if you had Websocket based subscriptions) while REST can be backed by traditional HTTP proxy.
thomasfedbalmost 7 years ago
I had hoped that GraphQL would come along with a solution for &#x27;live queries&#x27; - alas that seems to still be on the drawing board. Really looking forward to when &#x27;send me a list, and any changes to that list, and merge them together&#x27; is a problem I don&#x27;t have to put any thought into solving.
roadbeatsalmost 7 years ago
Could you all tell about your stack, too ? Do we have to use NodeJS in order to get GraphQL working properly ? I&#x27;m aware of the libraries available for other languages, but NodeJS seems to be the only platform with proper support. I wonder if there is any Go developers building servers with GraphQL.
评论 #17567044 未加载
sbinthreealmost 7 years ago
Much prefer REST assuming nested documents are aggregated by default into the parent. If it&#x27;s just an HTTP RDB client like some can be then not so much. Less data on wire doesn&#x27;t matter for server to server communication. I can see it for APIs whose sole purpose is low bandwidth client apps.
yen223almost 7 years ago
Yes.<p>The productivity gains from having a client-server interface that is dead simple to reason about more than made up for the initial investment cost. We can refactor API schemas without worrying about breaking existing client code. We also saw performance gains from saving on network round trips.
schicklingalmost 7 years ago
Almost all developers&#x2F;team who <i>actually</i> tried out and used GraphQL, will say the same thing: You never want to go back.<p>Most of the arguments against GraphQL that I&#x27;m reading here, seem to actually be misconceptions (or the GraphQL ecosystem not being far enough yet).
评论 #17569722 未加载
aclatutsalmost 7 years ago
I&#x27;ve been building a GraphQL only product for 1.5 years now. It was also the best scenario for graphQL because we were also rewriting an entire app from scratch.<p>For some background info this app has a huge feature set, low traffic, B2B, and at most 2 developers working on this app for about 1 year.<p>For the technical side I chose typescript from the back end and front end (Angular). This mean I could use the same typings from our ORM mongoose.<p>Very early on I was able to pick tooling that ending up being cutting edge compared to any other tool in any language, namely the tools where graphql-compose, grapqhl-compose-mongoose, and graphql-code-generator. In addition GraphQL lent itself pretty well to dependency injection on the server side.<p>It took about 6 months to get fully proficient, but it was completely worth it being able to use the same types for the front end and back end. GraphQL even made it possible to bootstrap types from mongoose into the server. A lot of time when dealing with 3rd party services I could copy the docs and turn it into types for the resolvers.<p>The biggest single benefit of it all was side stepping the middleware of Express. I didn&#x27;t realize how awful express middleware are, because you can&#x27;t really control the middleware chain very well. But the library with graphql-compose made chaining resolvers extremely precise, which was important.<p>Overall I love working with GraphQL but I realize that I probably could have done just as well with rest if the backend has decent middleware chaining i.e not express. For performance there is lots of options that are often built in like client caching, batched queries, whitelist queries, and persisted queries. It worked pretty well in a PWA too.<p>tl;dr<p>pros<p>- types everywhere!<p>- following the logic of any resolver is usually pretty straightforward.<p>- true middleware<p>- learned how to make good rest frameworks in the future.<p>cons<p>- hugely steep learning curve
ojralmost 7 years ago
my API uses a combination of REST and GraphQL, new api calls are written mostly in GraphQL unless its something like a batch job, or querying, modifying the database, Rest works better for those type of tasks in my experience.
chao-almost 7 years ago
So far so good, especially on the front-end. We love the queries, the caching downside don&#x27;t bother us <i>too much</i>, but mutations make me a little nervous (conceptually, ecumenically, grammatically...).<p>On the server side, it is a mixed bag. Defining a new type system on top of our existing one, and on top of the Avro schemas we have for inter-service communication, it feels... a bit much. Each layer has a purpose so I can&#x27;t advocate for removal, but it does feel silly at times. Also the documentation on pagination feels incomplete to the point of confusion, and depending on how you search for answers, you might find blog posts that add confusion rather than clarity.<p>Some additional friction came from the specific version of the Ruby server library we jumped in at. They went <i>a little overboard</i> in the amount of metaprogramming used by the DSL, and I say that as someone who enjoys metaprogramming shenanigans for fun on a Friday night! But it took a long time to understand why adding some custom behavior, in a way that seemed utterly necessary, was not possible (e.g. defining methods inside the DSL&#x27;s type block did not class_exec them into existence on the resulting class in any reasonable way). They have since released a new version whose main API is class-based, which is much more clear, enables everything I desire, and I am eagerly awaiting next month when we get to upgrade to that and refactor. Thanks to the maintainers for recognizing this was needed, and for doing the heavy lifting to pull it off!<p>What I enjoy about GraphQL conceptually is that it dodges a certain square-peg-round-hole issue I occasionally saw with REST, but in the same way that leaves me nervous that we&#x27;ll end up back at a land of inconsistent RPC spaghetti. In an API where an iron-fisted &quot;RESTful Actions Only!&quot; rule is enforced, many domains find <i>just those one or two actions</i> that feel like they are a better fit for their own unique verb, a custom-named action. The rhetorical-and-ontological escape hatch for REST&#x27;s limited verb set is to have an abstract &quot;resource&quot; that only has, say, a POST option. You can only &quot;create&quot; an &quot;&#x2F;recalculate_contacts&quot; resource, but never GET, DELETE and so forth. Or you PUT to &quot;&#x2F;contacts&#x2F;recalculate&quot;, or some other silliness that just feels too clever by half.<p>Those of us who were scarred by inconsistent, poorly-thought-out RPC spaghetti over the years cling to REST because it brought peace to our nightmares via simple rules that <i>almost fit</i> everything, and as a bonus, really gel with HTTP semantics. Because GraphQL&#x27;s Mutations really don&#x27;t specify much of anything, I immediately assumed it would descend into a sort of API moral decadence, but that has not borne out so far.<p>If anything, I am heartened to see that newer (though not necessarily younger!) developers, who grew up in a world where REST was all they knew, do not have this temptation to go off the deep end with action names, or to craft RPC-esque systems with ill-considered boundaries of behavior. For the most part they want to name things ala REST, because that&#x27;s what they are used to, except once in a while. So that is what our company goes with in terms of mutations: Wherever possible, name it for the CRUD action it represents. Only use a more unique&#x2F;one-off verb if it is truly justified.
sgk284almost 7 years ago
Eh... I&#x27;m torn on it and could write at length about this, but here&#x27;s my off-the-cuff thoughts. For context, my co-founder and I are quite active in the GraphQL community. If you&#x27;ve ever used apollo-cache-persist[1] or graphql-crunch[2], we authored those libraries. Our startup, if you&#x27;re curious, is a social podcasting app written in react-native (<a href="https:&#x2F;&#x2F;banter.fm" rel="nofollow">https:&#x2F;&#x2F;banter.fm</a>). We learned <i>a lot</i> of GraphQL lessons building it.<p>The tl;dr; is that graphql gives you a lot of flexibility and typed schemas are nice, but it doesn&#x27;t come for free and I miss the tooling around http.<p>Pros:<p>- Typed schema<p>- Custom queries retrieve all the data the client needs in one request<p>- Really easy to implement, both server-side and client-side<p>- Server-side, it&#x27;s trivial to have any field resolved in any way you want (redis, memcache, postgres, some random service)<p>- Easy and arbitrary mutations. There&#x27;s no pontificating over what verbs are the proper ones to us.<p>- If you use react, the community and ecosystem often assumes you&#x27;re using GraphQL, so it may make sense to use graphql just so you don&#x27;t swim against the current.<p>Cons:<p>- The payloads can quickly become huge because there is often a ton of duplication in a responses (depending on your query patterns). See this example on the SWAPI demo: <a href="https:&#x2F;&#x2F;bit.ly&#x2F;2uOFZBP" rel="nofollow">https:&#x2F;&#x2F;bit.ly&#x2F;2uOFZBP</a>. The result is 1MB of JSON, ~97% of which is data that exists somewhere else in the response already.<p>- Refactoring types is often impossible to do in a backwards-compatible way, even if the shape of the data is the same.<p>- You don&#x27;t know what data you&#x27;ll need in advance, so you&#x27;re basically doing all of your joins by going back and forth between the api resolver and your data sources (this can be alleviated with persistent queries, but those come with their own set of issues). A typical query to hydrate a response for a user&#x27;s feed in our app requests ~1,100 objects. After caching and consolidating queries into multi-gets, it translates to about 50 distinct DB queries.<p>- Tooling: Working at the HTTP level simply has better tooling and tons of infrastructure around caching and serving content (varnish, nginx, etc...)<p>We found that graphql payloads were so large that older mobile phones were spending significant time parsing them. We created graphql-crunch to de-duplicate responses before sending them over the wire. This led to nice perf improvements on mobile platforms. It also gave us referential equality when persisting the results to cache, allowing us to reduce a lot of work client side.<p>If you&#x27;re going to use GraphQL, embrace the javascript ecosystem. Also use Apollo[3]. Also use DataLoader[4]. Roughly 40% of our queries get resolved for &quot;free&quot; by data loader.<p>If I were to do it again, I&#x27;d at least prototype a REST-api with resources designed specifically for http cache-ability (that is, break out session-specific resources&#x2F;attributes vs shared resources) and see if HTTP&#x2F;2 multiplexing + nginx caching + etags results in a good client experience. But I also mostly work on the backend while my co-founder mostly works on the frontend, so we have different desires and constraints. Ideally, as few requests as possible would make it to code that I wrote. With GraphQL that&#x27;s nearly impossible.<p>[1] <a href="https:&#x2F;&#x2F;blog.apollographql.com&#x2F;announcing-apollo-cache-persist-cb05aec16325" rel="nofollow">https:&#x2F;&#x2F;blog.apollographql.com&#x2F;announcing-apollo-cache-persi...</a> [2] <a href="https:&#x2F;&#x2F;github.com&#x2F;banterfm&#x2F;graphql-crunch" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;banterfm&#x2F;graphql-crunch</a> [3] <a href="https:&#x2F;&#x2F;www.apollographql.com&#x2F;server" rel="nofollow">https:&#x2F;&#x2F;www.apollographql.com&#x2F;server</a> [4] <a href="https:&#x2F;&#x2F;github.com&#x2F;facebook&#x2F;dataloader" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;facebook&#x2F;dataloader</a>