News for hackers. Stuff that matters.
Re:SPAs Were a Mistake by nrb on Wednesday March 02, 2022 @11:05PM (#30537045)
GraphQL is such a quality of life upgrade coming from this environment, especially at the scale where your frontend teams are potentially larger and shipping more than the teams closer to the SQL can provide.
Re:SPAs Were a Mistake by tored on Thursday March 03, 2022 @05:00AM (#30539145)
GraphQL is a consequence of the SPA design, a bad design leads to a worse fix.

The drawback is that the frontend now has its own schema, often it starts as a naive direct mapping of the real schema.

Thus any changes in the real schema also need to change the frontend schema and every use of it, or the mapping to the frontend schema needs to change.

Eventually these two schemas will diverge because it is not feasible that every schema change results in frontend change. Especially if the idea is to have two different teams working from either side, then the backend team can’t wait for the frontend team therefore the schema mapping will change.

And the thing is that the frontend shouldn’t be aware of how the backend schema is constructed, if the User model is separated into three different tables, because of some technical reason, that should not change how the frontend operates. The frontend understanding of what a User is shouldn’t be the same as the backends.

Therefore ideally frontend schema and the backend schema will always differ. They don’t view the world the same way.

However what you now have is a slow mapper between the frontend schema and backend schema.

The point of relationship databases is that you can view your data from different perspective by doing different SQL queries. That is already built in. But now we have invented yet another layer on top of SQL, usually in combination with the already monstrosity called ORM.

Re:SPAs Were a Mistake by tekknik on Thursday March 03, 2022 @07:21PM (#30548909)
What a tortured usage of GraphQL. Schema files are automatically generated by the backend, and components pull data that they need, and know more. If you find yourself changing schemas constantly, then you’re not defining them in a scalable manner. You’ve basically misused the tech, and blamed it on the tech instead of your misuse.
Re:SPAs Were a Mistake by tored on Thursday March 03, 2022 @11:22PM (#30550669)
That is even more horrible what I thought. Automatically generate schemas 1:1 and then expose it. Let me guess tons of information leakage, ddos attacks and queries not hitting indexes. This is absolutely the worst idea I come across in web development. Horror.
Re:SPAs Were a Mistake by midrus on Saturday March 05, 2022 @01:33AM (#30564941)
GraphQL is just another artificial solution to a problem created by SPAs themselves. Same as SSR, hydration, server components, client side routers, dynamic bundles loading, dynamic translations loading, etc, etc, etc. A whole industry of workarounds for a broken idea. Now 10 years after SPAs became popular we starting to approach a point were we almost have what we already had.
Re:SPAs Were a Mistake by int_19h on Thursday March 03, 2022 @01:33AM (#30537858)
What I really don't get is why we don't just expose SQL directly at this point. Is it just security? Database servers have fairly extensive authentication and authorization models.
Re:SPAs Were a Mistake by littlecranky67 on Thursday March 03, 2022 @03:03AM (#30538378)
Authorization & access restrictions. Yes, you can go quite far with table/row/column permissions, but a lot of business logic cannot be modeled using just those (i.e. "user cannot place orders if total outstanding invoice payments surpass value $X").
Re:SPAs Were a Mistake by dragonwriter on Thursday March 03, 2022 @05:08AM (#30539188)
The combination of DB permissions, DB constraints, and simple (SQL, not procedural language) triggers gets you a lot, including the ability to enforce rules like the one you mention.
Re:SPAs Were a Mistake by littlecranky67 on Thursday March 03, 2022 @06:24AM (#30539617)
Yes, you can enforce a lot through SQL triggers/stored procedures etc. But you often end up abusing your DB/SQL as a business logic layer, where your business logic is encoded in a huge set of row/column permission and custom SQL triggers . This tightly couples your database into your whole business application stack.

Especially in Oracle PL/SQL, I've seen this often abused to an extend where no one ever understood the whole business logic anymore (as logic was spread out in frontend, middle-layer services, and DB mumbojumo), and the database became a fragile core-piece (with a significant vendor login) and hindered all sort of future development.

Seriously, your business logic should be modelled in code, ideally in some sort of service layer (which does not necessarily mean microservices!).

Re:SPAs Were a Mistake by dragonwriter on Thursday March 03, 2022 @10:20AM (#30542149)
> But you often end up abusing your DB/SQL as a business logic layer, where your business logic is encoded in a huge set of row/column permission and custom SQL triggers.

That's not “abuse”. Admittedly, it's no longer an essential best practice for most systems, the way it used to be viewed, because it's more common to have a single application which fully owns the database and not to (at least in idealized theory, though very some ops staff still end up with direct access to the prod DB) allow access by other means, so in theory it doesn't tend to be necessary to avoid either circumvention of rules or (inevitably inconsistent, as well as expensive to maintain) duplication of logic.

Re:SPAs Were a Mistake by int_19h on Thursday March 03, 2022 @04:57AM (#30539128)
Then why aren't we working on improving the databases to allow for such complex rules, and instead wrap it in another layer (often multiple) to do all this stuff there?
Re:SPAs Were a Mistake by littlecranky67 on Thursday March 03, 2022 @06:25AM (#30539622)
because a database should not hold your business logic. It should hold your data, and that it can do well. See also my other post on parent for more reasoning.
Re:SPAs Were a Mistake by funcDropShadow on Thursday March 03, 2022 @09:50AM (#30541735)
I beg to differ in many interesting cases, we put at least some parts of the business logic into the database. The table design is a direct consequence of the business logic, the same is true for constraints and triggers.
Re:SPAs Were a Mistake by int_19h on Thursday March 03, 2022 @06:36PM (#30548580)
Why shouldn't it? As noted above, database servers already have most of this (security) logic in them - likely tested much better than whatever you can write on top of the database yourself. And given how many apps are basically just CRUD, why reinvent the wheel every time?
Re:SPAs Were a Mistake by yencabulator on Saturday March 05, 2022 @11:52AM (#30569139)
Mostly because the tooling is so bad. Or do you have unit tests, lint, and easy version control for your stored procedures? Are they written in a way that matches at all what rest of your programming is? Can you import a randomly picked utility library?
Re:SPAs Were a Mistake by int_19h on Saturday March 05, 2022 @08:34PM (#30574081)
The next obvious question is, why is tooling so bad then? And would it have been so bad if we invested as much into RDBMS as we did into Node.js web-frameworks-of-the-day.
Re:SPAs Were a Mistake by yencabulator on Sunday March 06, 2022 @09:34PM (#30583591)
Writing the next modern elegant artisanal javascript webshit is a lot easier than making a sandboxed programming environment that integrates tightly with a production quality database engine and has a good story for testing, deployment, debugging, etc.
Re:SPAs Were a Mistake by qw on Thursday March 03, 2022 @04:29AM (#30538967)
Even if you solve the security issue, a query can easily bring down the server if it has a complex join query.

This could be solved by only exposing stored procedures, but that just moves the code to the database server instead of the REST service with the same problems as before.

Re:SPAs Were a Mistake by tored on Thursday March 03, 2022 @05:33AM (#30539343)
You can also use a VIEW.

How does GraphQL make sure to respect table indexes? If not you get a super slow query.

Re:SPAs Were a Mistake by qw on Thursday March 03, 2022 @05:56AM (#30539473)
You can still get performance issues with a view if you "select *" on a large amount of data, or join with other views. By exposing the SQL to a web page, you also open up for DDoS attacks more easily, as you can write complex SQL queries

You can get the same problems with GraphQL or stored procedures too of course, if the queries are not optimized correctly

Re:SPAs Were a Mistake by MonaroVXR on Thursday March 03, 2022 @10:38PM (#30550411)
So what's the solution to this?
Re:SPAs Were a Mistake by int_19h on Friday March 04, 2022 @12:41AM (#30551093)
Performance quotas.
Re:SPAs Were a Mistake by tekknik on Thursday March 03, 2022 @07:22PM (#30548914)
Because a human is writing the resolvers pulling the data from the database. Set whatever index you want to use.
Re:SPAs Were a Mistake by tored on Thursday March 03, 2022 @04:13AM (#30538872)
Just give the end user an account to phpMyAdmin. Done. No complex frontend framework required.
Re:SPAs Were a Mistake by littlecranky67 on Thursday March 03, 2022 @06:32AM (#30539652)
You wouldn't belive how often companies use excel with external datasources like this. Excel basically is the common-ui for a lot of people.

And most of the projects I worked on in my professional career as a webdev, were replacing such workflow with a proper web application, because excel does not scale and eventually people fuckup their data.