Live data from Hacker News

GraphQL Query Generator

blog.graphqleditor.com

41–49 of 49 posts

Re: GraphQL Query Generator

#41

We're looking at adopting GraphQL and for writing a CRUD app it seems insane. Being able to project out individual fields seems like a niche benefit for bandwidth constrained devices. Instead of doing joins in an RDBMS you write a dataloader which merges select queries. The queries themselves seem like a lot of repetition in the client codebase, plus the complexity of the server-side implementation. Am I alone in thi…

Not saying it's not still ridiculous for your use case, but if you're using Apollo as your GraphQL server, you can still do your joins without data loaders. The 4th argument passed to your resolvers [0] allows you to check if children properties have been requested and then you can use joins to "pre fetch" those without data loaders. Haven't done it myself yet but someone told me about it on HN a while back.

0: https://www.apollographql.com/docs/apollo-server/data/resolv...

Re: GraphQL Query Generator

#42

Earlier quoted context omitted.

Have you looked at Hasura (hasura.io)? Allows you to carefully expose your database as an API, while allowing you to build serverless endpoints for validation, business logic and side effects. Bakes in authorization as a first class concern. There are some other similar alternatives that do much the same. Think it's a mistake to consider GraphQL as a drop-in replacement for REST, writing a vanilla GraphQL server is i…

The biggest pains with hasura are managing migrations across a large development team and adding business logic.

That's fair. I haven't used it in that context.

Re: GraphQL Query Generator

#43

Earlier quoted context omitted.

Although I haven't used it personally, I can see it being very useful for APIs where the "objects" involved contain many fields/relations. Rather than coming up with a limited set of filter/query parameters, you can take advantage of a query language with tooling. That being said, one of the things that irks me about most* GraphQL implementations is that they seem to do joining entirely server-side. This makes sense…

How often do you need to use a join from the client? It's not like "rest" has built-in joins either.

While it's true that REST has no concept of joins, when retrieving designing an API using REST, one often has to decide whether to return data related to an object as part of a query for the object, or to force the client to make secondary lookups.

Regarding GraphQL, one of its big selling points is that you can query not only for specific fields, but fields in nested data as well.

Lets take two possibly equivalent queries, modeled on the data discussed in the GraphQL tutorial[0]:

  # REST Call
  GET /hero?primary=true

  # GraphQL Query
  {
    hero {
      name
      friends {
        name
      }
    }
  }
Ideally, these queries would result in the following SQL query when one wants to also get the primary hero's friends:

  SELECT
    heroes.name,
    (
      SELECT heroes_inner.name
      FROM heroes AS heroes_inner, friendships
      WHERE friendships.left = heroes.name AND
            friendships.right = heros_inner.name
    )
  FROM heroes
  WHERE name = ? AND primary = true;
(This query might not be exact, but it should get the meaning across.)

Of course, this presumes that the REST query selects friends names as part of the request, and that the client doesn't have to manually perform a join/secondary lookup to retrieve additional data. If it doesn't, then you might have to perform additional REST calls to get all the friends of the primary hero.

[0] https://graphql.org/learn/queries/#fields

Re: GraphQL Query Generator

#45

We're looking at adopting GraphQL and for writing a CRUD app it seems insane. Being able to project out individual fields seems like a niche benefit for bandwidth constrained devices. Instead of doing joins in an RDBMS you write a dataloader which merges select queries. The queries themselves seem like a lot of repetition in the client codebase, plus the complexity of the server-side implementation. Am I alone in thi…

>Am I alone in thinking this is a ridiculous solution to replace traditional REST endpoints? You're not alone. I went down the GraphQL path a year and a half ago. I was telling everyone it was going to be the future, then I got tired. GraphQL requires a lot of configuration and setup to get working right. The decent implementations of GraphQL are all proprietary solutions like Apollo. When you feel like you're spendi…

>Don't get me started on things like authentication, file uploads and protecting your server from being DDoSed or driving up your cloud computing bill by someone creating expensive queries.

These are API Management requirements, and they require a different treatment from the traditional approach, just granting access and checking rate limits is not enough. One approach is to statically analyze the query and determine how it will affect your backend, and how much data it intends to retrieve. Products are starting to come into the market, recently IBM API Connect had this announcement about it: https://community.ibm.com/community/user/imwuc/blogs/rob-the...

Re: GraphQL Query Generator

#46
post #20

Earlier quoted context omitted.

The idea is that you can select the exact data fields you need for your UI. In a traditional REST-like response, say for a User model, you may receive all data (within authorization limits) about the user in the response when all you needed was the first_name field. With GraphQL you would just receive first_name without the rest of the unneeded fields, thus reducing the amount of data sent.

If you’re the only consumer of your api then why are you exposing more data than you need? I’ve never seen an internal rest api that was 100% restful. It was restLike. So if you have consumers of your api then allowing them to pull only what they need makes sense. But for an api where you are the only consumer, it makes no sense.

It's interesting, because I always argue that first-party usage is GraphQL's sweet spot (over third-party).

To avoid repeating myself, here's a minor tweet thread from a few weeks ago: https://twitter.com/andrewingram/status/1278019358703435777

Re: GraphQL Query Generator

#47
post #20

Earlier quoted context omitted.

The idea is that you can select the exact data fields you need for your UI. In a traditional REST-like response, say for a User model, you may receive all data (within authorization limits) about the user in the response when all you needed was the first_name field. With GraphQL you would just receive first_name without the rest of the unneeded fields, thus reducing the amount of data sent.

If you’re the only consumer of your api then why are you exposing more data than you need? I’ve never seen an internal rest api that was 100% restful. It was restLike. So if you have consumers of your api then allowing them to pull only what they need makes sense. But for an api where you are the only consumer, it makes no sense.

If you have more than one developer working on different features, it’s inevitable they’re going to need different data. Unless you have a tight feedback loop between frontend and backend devs, you’re going to end up with pending unresolved issues requesting they add another field to be returned on a specific, custom “rest-like” endpoint. If you instead put the onus on the frontend to allow arbitrary field requests (of course within limits, typed and auth’d), this is no longer an issue. Of course the api has to have a schema defined, so there could be a request for a new field to be added there. But if all your endpoint returns is what we need NOW, then you will inevitably have to add more data to the endpoints later with new features. This isn’t of course the only benefit of GraphQL, but it’s certainly a nice convenience for those having to make those requests.

Re: GraphQL Query Generator

#48
Hey! I helped write the GraphQL query generator! Thank you so much for highlighting our library! This was a very pleasant surprise in the morning. I think your article does a very good job at summarizing our library, its benefits, and its uses. I would love to know about your experience using our library. In any case, this was super cool!

Re: GraphQL Query Generator

#49

We're looking at adopting GraphQL and for writing a CRUD app it seems insane. Being able to project out individual fields seems like a niche benefit for bandwidth constrained devices. Instead of doing joins in an RDBMS you write a dataloader which merges select queries. The queries themselves seem like a lot of repetition in the client codebase, plus the complexity of the server-side implementation. Am I alone in thi…

I don't get the attraction for a standard crud app either.
Post reply on HN