Live data from Hacker News

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

news.ycombinator.com

71–80 of 182 posts

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

#71
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.

* Watch out for bad implementation of the GraphQL API (this will definitely result in bad performance).

* Design the GraphQL schema that you want the user to see/perceive. Not every object or field in your database needs to be exposed via the API the way it is.

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.

As a result of our codebase, we've tried GraphQL in:

* 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.

* Python (graphene) - We've had no issues so far. We worked around it.

* 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.

* Elixir (Absinthe) - My coworker worked on this part. He did not complain. So I'm assuming he had no issues.

The "Learn * in a day" 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.

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.

Due to poor documentation/examples provided, ramping up people with GraphQL is hard. Most first iterations I've had to review were slower than our REST APIs because of unoptimized code. Sitting down for a few minutes solves that problem.

To ramp up people at work place, I ended up having to do this:

* Ask people to use the GitHub v4 API to checkout GraphQL.

* Make them build a GraphQL server for a blog app.

* Dive straight into whatever feature/API they would build.

* Review their work a few dozen times and show them optimization tricks.

My most valuable lesson: When in doubt, dig into the source of these libraries.

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

#73

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…

"We moved to GraphQL because things were bad, and now things are good. GraphQL is amazing". I don't want this to come off as a personal attack (and I apologize if it does), but your comment contains absolutely no information whatsoever regarding a specific situation/use-case, nothing from which the rest of us can formulate our own opinions on the REST/GraphQL discussion.

>we were spending a lot of client time fetching deep trees through resource links

>it solved a lot of the administrative and philosophical headaches

>considerably reduced the number of connections

>considerably reduced wasted data

>made our client code so much simpler through easily grokked queries

I feel that grandparent does contain information which might be valuable for adoption.

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

#74
Yes.

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't regret it so far. There a various advantages (and disadvantages) [0] using GraphQL.

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/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/MobX. Often it is even possible to remove these state management libraries altogether.

- [0] https://www.robinwieruch.de/why-graphql-advantages-disadvant...

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

#75
post #59
post #46

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. 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 program…

It's not impossible in Java but it does require a strong grasp of graphql-java's execution model and the DataFetchingEnvironment and associated classes. We accomplish something similar to what you desire when querying our time series database via GraphQL. The big difference between Java and Javascript when it comes to GraphQL is the amount of noise, tutorials and examples on the Javascript side far outweigh other opt…

Do you have a kotlin graphql library you'd recommend. I just started working on Kotlin with GraphQLJava. I saw graphql-kotlin, but that appears to have been updated like a year ago. I've been using graphql-spqr. Mixing kotlin and java in my projects, to get around the annotation bug.

I do agree on the noise and lack of tutorials. I'm getting ready to present on a GraphQL option. We don't want to use javascript. The tutorials for java are a bit cumbersome.

Btw I'm really liking apollo.

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

#76
It makes many things easier and many things harder. The lack of really good backend libraries/frameworks outside of NodeJS is the most concerning thing.

Also; debugging and monitoring GraphQL APIs sucks. Considerations:

- 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.

- Because of this, any GraphQL query is capable of returning multiple errors.

- Rate limiting is exceedingly difficult due to nested resolvers. I've seen solutions which involve annotating your schemas with "cost" numbers, and only allowing each query to run up to a maximum "cost" before failing by dynamically adding the costs of each field they request. Traditional rate limiting doesn't work.

- Traditional APM platforms also don't work. Prepare to adopt Apollo Engine and pay them $600/month on top of the money you're already paying New Relic or Datadog.

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

#77
Who says GraphQL is not RESTful, though?

You have resources represented as a graph and you'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.

Nothing about REST ever said that a resource locator had to be a URL, or that a single resource can't represent a collection of resources.

That's all GraphQL does, IMO. It lets you more flexibly and expressively ask for stat of a collection of resources.

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

#78
As a consumer of APIs I vastly prefer REST APIs.

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't like to talk to each other. As a user, I just want to GET /foo, with a good old API token I pasted from your dev docs, and move on to the next thing. I don't want to spend time figuring out your database schema. Or perhaps I've just yet to see single good public GraphQL API. I just recently had look at the Github GraphQL API and it's non-existent docs (no, I don'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.

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

#79
post #76

It makes many things easier and many things harder. The lack of really good backend libraries/frameworks outside of NodeJS is the most concerning thing. Also; debugging and monitoring GraphQL APIs sucks . Considerations: - 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. - Because of this, any GraphQL…

I’ve only heard positives about Absinthe for Elixir fwiw.

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

#80

my experience is just ok. as someone here puts it, great for frontend devs but bad for backend devs. if you have db schemas on the backend if using orm, get ready to duplicate them again for graphql. 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. my conclusion is that, since im a fullsta…

> 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. Wouldn’t you need to do this in some form anyway (since those fields would be displayed or used in some way)?

well, it won't be just a simple GET /user/1 anymore. it will be like: user { id name role status age sex address group { id name } etc etc }
Post reply on HN