Today at work someone presented on graphQL, and there was an interesting discussion among all the engineers in the room about it. There was been a few times where I have had the chance to learn about graphQL, and I feel like I often leave thinking, "hey, that's a cool" but then never actually start using it in my development. Welp, that has been somewhat of the case again. Lol
Ok, so the first thing that I really need to make clear right off the bat is that graphQL is NOT and kind of has nothing to do with graph databases. Graph databases are the things that Facebook, for example, uses to represent relationships between people. In mathematics a graph is a way of representing data that involves "nodes" and "edges". Graph databases such as Neo4j and OrientDb model data in terms of node-edge relationships, but graphQL is a completely different thing and can work with any old relational or noSql database.
The real power in graphQL is that it makes the "read" piece of your CRUD operations super flexible yet easy to build. Suppose for a minute that you have a postgres table full of data, and each row has 100 columns. Say you wanted to pull an object that had only a subset of the available properties, or possibly a few rows , each with only a row columns worth of data. With graphQL it's cake to do this because the way it is setup is that the consumer can specify exactly the shape of the object he or she wants. The api only has to know what is the largest possible object that can be returned (and so schema changes are usually additions of new fields), and it is quite easy when querying to ask for only specifically what you need.
Another benefit of using graphQL is that it can consolidate your request logic so that the frontend sees it as one single request and response even though the graphQL layer could be calling to multiple endpoints, rearranging things, etc. We heard a story where this was especially useful to our ios team who could pull a lot of logic out of the front-end app which was tough to patch bugs and deploy and move this code over to the server side where it could be more easily and quickly deployed. Another good point to make here is that your graphQL server can be much more powerful than a user's device (think compared to a random cricket wireless cell phone), and it could be on the same VPN or at least hosted "closer" to your other endpoints / databases to which it may be communicating.
The query flexibility makes graphQL especially great for apis that have multiple consumers since in theory any should should be able to query anything he or she wants without the backend developers having to write a special endpoint "/whatever" that returns these things, but not these other things, and some of those things... For these use cases graphQL can be a godsend and can really make what may have been tons and code before just given to you right out of the box!
Yep, graphQL normally runs on its own server. I haven't dove too deep into the code, but one of my colleagues said that you really just set up a modified express node.js script, and that's the graphQL endpoint! graphQL can work with other apis or connect directly onto a database (and it supports many different databases).
During the presentation there was a demo of the ___ dashboard. It is a pretty neat little SaS service that hooks into your graphQL
The posts on this site are written and maintained by Jim Lynch. About Jim...
Want FREE access to
my daily stock tips
"The Triple Gainers"?
Sign up here!