I don’t like GraphQL, so how about JSON and TypeScript?


I will be honest with you, when I first saw GraphQL’s syntax I felt a familiar unpleasant feeling, the same feeling I felt when looking at the syntax of PHP, Perl, or Bash.

I personally think that JSON is a far more elegant way of representing data when compared to XML, YAML, or ProtoBuf. It’s minimalist, easy to read, consistent, and it is seamlessly integrated with JS/TS or Python.

So my heart sinks when I see how JSON gets mutilated by query languages that claim to have a way of getting things out of the database that feels “familiar.”

I know GraphQL services and declarations were meant to be language “agnostic.” So the problem got “solved” by creating a new language. Personally, I find this is a bit funny. To me, it seems similar to a situation when you don’t want to give someone a preference so you just give a preference to somebody outside of the group who is equally disliked by everybody.

Well, since JS/TS is a de facto language of the web that will be used for querying doesn’t it follow that it would be preferable to piggyback off of it to make everybody’s life easier?

But enough complaining, I will try to show you what I mean with concrete examples. I decided to base them on the official GraphQL documentation. ()

Using TypeScript and JSON for Querying a DB

Here is a small contrived example of how I would personally like to query a database. Feel free to disagree.


I really wanted to keep it short yet clear enough for my intentions to be understood.
I really think that something as simple as what has been outlined above — of course not without its own challenges — could be a way of querying databases in a similar fashion to GraphQL while being much more “elegant” due to the fact that it is nothing more and nothing else but the client-side TS that you would have to write either way.




Whether I shall turn out to be a hero of this book these pages must show

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Qt Call Slot Thread


Top Articles of the Week — JavaScript, Node, React, Redux, MongoDB, Docker, ReasonML, Responsive…

Vue.js Custom Event: Emit Multiple Values from Child to Parent

Intro to Sequelize — ORM in JavaScript

Unique Elements in AmplitudeJS

Beginner’s guide to JavaScript’s map()

I got this error when I copy and pasted the path

五個實用的雅思考試準備網站 Five useful websites for IELTS preparation

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kirill Novik

Kirill Novik

Whether I shall turn out to be a hero of this book these pages must show

More from Medium

Narrow Down Types With Typescript Generic Constraints

TypeScript: Explicit vs Implicit type annotation 🤔

TypeScript Type Gymnastics: Array lengths implement numerical operations

Understanding TypeScript type inference and const assertions

A plane dashboard with lots of buttons and levers, and a pilot and copilot