News for hackers. Stuff that matters.
Re:Where in the HypeCycle is GraphQL? by tyingq on Tuesday July 13, 2021 @10:54AM (#27821733)
I've only had a little experience with GraphQL, but I'm finding it frustrating because designers of the APIs tend to normalize structures since the backend is often a relational (or graph) database.

For example, rather than having top level "admin contact email" and "business contact email", API designers will have a sub graph of contacts, with label->email. (Note that this is the trivial example, it gets much worse)

Most of the time, I need a flattened version to actually do the work. Now, with SQL, that's not an issue because I can put a query together that flattens/joins as needed. But, with a GraphQL result withs lots of edges and nodes, I can't do that simply. I have to write some bespoke recursive walker to pull the data back up.

I understand I could fix this with the schema, but these aren't my APIs, I'm just a consumer. There doesn't seem to be some universally supported way to do the equivalent of a join.

Or, more simply, the culture around REST/JSON seems to prefer flatter structures, but the GraphQL crowd tends to like more nested structures...even when it's not really needed.

Edit: Also, it's not so simple to make a universal, declarative-driven "flattener", as the nested structures vary pretty wildly in how they are done.

Re:Where in the HypeCycle is GraphQL? by joshribakoff on Tuesday July 13, 2021 @11:11AM (#27821955)
I don’t align with your view, let me share my view.

The GitHub web hooks (which is basically REST) post a deeply nested json full of nodes (that you “might need”) which I don’t need, and lacking info I do need (ended up having to do another round trip to GQL after receiving the bloated web hook payload)

I have seen suboptimal APIs on both technologies.

If you don’t have control over the API, it doesn’t matter if it uses SQL, so following your logic the issue seems to be that you cannot change the API, not the tech it uses.

Re:Where in the HypeCycle is GraphQL? by tyingq on Tuesday July 13, 2021 @11:22AM (#27822073)
We're probably closer on views than you think. REST apis can return unneeded nesting too...I get that.

The difference is the culture/background/ecosystem around GraphQL, which makes it happen more often. It's the easy path there.

Re:Where in the HypeCycle is GraphQL? by nivertech on Thursday July 15, 2021 @07:49AM (#27843664)
It's recommended to use nesting in GraphQL objects (both inputs and responses) for backward- and future compatibility.

But your problem is mostly because the API is not under your control.

In GraphQL backends it's OK to add special queries adapted for specific UI/UX (I think it's the whole idea behind the BFF - Backend-For-Frontend pattern).

I.e. you can choose between Design-first (data-centric) or Client-first (optimized for rendering on the Client/Front-end) GraphQL schema methodologies.

In the Client-first GraphQL schema you can have queries returning flattened data.

A non-standard approach is to run transformations, i.e. you specify directives how to transform the GraphQL operation responses. This can be for flattening, aggregations, calculating statistics, or joining results of the different queries.

https://www.graphql-mesh.com/docs/getting-started/mesh-trans...

Re:Where in the HypeCycle is GraphQL? by nodejs_rulez_1 on Tuesday July 13, 2021 @11:46AM (#27822393)
GraphQL should have been called FacebookQL and microservices should have been called Netflix-services.

Otherwise hype-following developers think it's a good idea to just go ahead and use them, despite not having the unique needs and resources of neither of those megacorps.

Re:Where in the HypeCycle is GraphQL? by jmondi on Tuesday July 13, 2021 @12:03PM (#27822627)
With GraphQL, I can generate most of my client libraries while, and when I am writing a web client using typescript, I have full type checking on my apps. This makes me as a solo developer so much faster than using rest, with 0 client library generators, and 0 type safety. If my API changes response, my front end generated library will fail compilation with a type error.

Moral of the ramble, new tech is great – sometimes.

https://www.graphql-code-generator.com

Re:Where in the HypeCycle is GraphQL? by alephu5 on Tuesday July 13, 2021 @12:34PM (#27823037)
> With GraphQL, I can generate most of my client libraries while, and when I am writing a web client using typescript, I have full type checking on my apps. This makes me as a solo developer so much faster than using rest, with 0 client library generators, and 0 type safety. If my API changes response, my front end generated library will fail compilation with a type error.

> Moral of the ramble, new tech is great – sometimes.

> https://www.graphql-code-generator.com

You can do this with a boring REST API too. Most frameworks can automatically generate a swagger file, and there is a tool to generate clients from this in lots of different languages.

Re:Where in the HypeCycle is GraphQL? by irjoe on Tuesday July 13, 2021 @11:24AM (#27822096)
I really wish the GraphQL alias syntax supported something like:

  query {
    users {
      email: contact.email
    }
  }
Re:Where in the HypeCycle is GraphQL? by ako on Tuesday July 13, 2021 @11:00AM (#27821824)
Fair point: GraphQL is mostly a data retrieval protocol that helps you retrieve specific data as stored by the app. SQL also provides data transformation with grouping, aggregations, functions, where clauses, views, subqueries, etc. You could implement that in the resolver, but then you're at the mercy of the api implementer.
Re:Where in the HypeCycle is GraphQL? by joshribakoff on Tuesday July 13, 2021 @11:17AM (#27822022)
You can use SQL in your resolver, like you mention. Note you’re also at the mercy of the API implementor if they use SQL in a REST endpoint.

GQL also has some affordance for renaming fields (although admittedly nothing like SQL for the client, if you did allow running sql via the client it would be harder to sanitize, so this is a “feature” not a “bug”)

Re:Where in the HypeCycle is GraphQL? by ako on Tuesday July 13, 2021 @12:06PM (#27822670)
Odata or postgrest offer rest apis that are closer to the functionality of Sql.
Re:Where in the HypeCycle is GraphQL? by ericwooley on Tuesday July 13, 2021 @10:59AM (#27821798)
I never got the edges and nodes thing, and every time I have worked with a graphql endpoint that did, I was indeed very annoyed.

Feels like something that came with a graph database, and people tried to blindly copy it.

Graphql code generator is great though. Absolutely wonderful. Makes it really hard to go back to rest.

Re:Where in the HypeCycle is GraphQL? by hirundo on Tuesday July 13, 2021 @11:36AM (#27822253)
We left out edges and nodes from our GraphQL API because of how confusing they are. But the downside is that we had to add a <collection>Stats object for each collection type to support meta data like the count. Still it seems to be easier this way for non-developers to learn. And the API consumers are mostly not developers, like account managers and accountants, usually via GraphiQL.
Re:Where in the HypeCycle is GraphQL? by dustymcp on Tuesday July 13, 2021 @02:34PM (#27824483)
ever tried swagger and nswag for client generation in rest it does the same thing but requires abit of a wire