Hacker News new | ask | show | jobs
by xwowsersx 1108 days ago
This seems completely backwards and contradictory to me:

""' Let's return to the user profile example. With GraphQL, instead of the frontend deciding what user data to display and where, this decision-making process can be moved to the server. When the GraphQL server receives a request for user data, the request includes specific fields that the frontend wants. In response, the server sends back exactly what was requested - no more, no less. """

First, it says that the server, instead of the FE decides. Immediately after, it says that "the request includes specific fields that the frontend wants".

If the request specifies the particular fields it wants, then it is the FE deciding what data to display...

So I think ChatGPT has this totally wrong. I'd love to be corrected here, but my understanding is that a (perceived) problem with REST, or at least the way it's used, is that the backend often requires specialized endpoint that anticipate the needs of a particular frontend context. In that sense, they are tightly coupled. This happens because, in order to avoid having to execute dozens of requests in order to fetch the data needed on a particular page or screen, you write some endpoint that is intended, from the outset, for a particular UI in the client app. You also have the opposite problem where an endpoint returns far more data than the client cares about in certain spots. Enter GraphQL: since the client queries for what it needs, it can specify precisely what it wants, ranging from a single nested field to a much more complicated object.

Note: I'm not judging the merits of this GQL pitch. I'm just saying that's the argument, as I've understood it. That being the case, not only is ChatGPT contradictory in the above cited section, but it also has the whole argument backwards.

As always, very glad to be corrected on any of this.

2 comments

Yeah I had a similar reaction to yh first response. But after I asked a follow up 'But the frontend is still deciding what data to ask for', it gave me a better explanation and then an example.

That final part made it clear to me (assuming it's not a hallucination!).

Huh. I'll read again and closer. I still think it may very well be wrong hah. This is a funny feeling when examining a ChatGPT response closely...you don't know if it's futile because it really just wrong or if there's more there. Maybe I'll continue the conversation with it to tease this out some more. Glad you shared the chat.
the server decides what's on the menu.

the client picks items from the menu

the server sends back exactly those items.

in REST, the server sends all of the items on the menu! as a result you end up creating many different menus.