Learning about GraphQL

Tre'von Mitchell
3 min readOct 18, 2021

--

What is GraphQL?

In this article, we will go over a tech stack called GraphQL. The main question you want to know here is what is GraphQL? This will be a brief review on GraphQL and if you want to learn more about GraphQL, there will be some resources down at the end of this review. GraphQL is a query language, which is what the QL stands for at the end. This is a language for your API and it is so different from anything that you may have worked with before on a standard API. So usually when connecting with the client and server, If you wanted to fetch data from the Spotify API, you will tell Spotify like hey Spotify this is the information I want from you. How that would normally work, is that you would have a specific endpoint or a URL you want to target, right? That URL is what will determine what data will come back. You can pass in options to a URL and the options you passed in can change the outcome of the data or what comes back inside of it. Dealing with a REST API, you can fetch a URL and the URL will return a JSON or JavaScript object full of data.

With GraphQL, instead of an API where you hit a URL and accept whatever data is coming back, GraphQL allows you to ask for a specific kind of data.

Describe your data

{
Project {
name: String tagline: String contributors: [User] }
}

In the example above, we are defining the way our data looks like, which is a Project with a name, a tagline, and contributors, then for the example below you ask for what you want. This example is actually the query. So instead of hitting an API and just accepting data, you can say hey give me the Project with the name GraphQL and return the tagline.

Ask for what you want


{
project(name: "GraphQL") { tagline }}

The results that come back are what exactly what you asked for with the example shown below, which is an object with Project and tagline instead of a bunch of stuff that you may have not asked for.

Get predictable results

{      "project": {                    "tagline": "A query language for APIs"                 }}

For filtering out fields that you are not going to use, GraphQL allows for relational queries that will save you time. For example, YouTube API, when you target the URL, you will get a list of videos which is the video IDs but if you want all of the information about that particular video, you have to go back to the API and basically say “hey I have this ID but can you give me information about this particular video with this ID”. With GraphQL, you can do extremely relational queries that only make it where you only have to do one spin to the API and data comes back.

To sum it all up, GrapQL is a query language, and it's a way to get data from an API into your application.

GraphQl is a specification and it was created by Facebook but it's not an implementation so there is no install GraphQl anywhere for it. To use GraphQL, you need to use an implementation of GraphQL and you can use it on any sort of platform.

Thank you for checking this article out, hope it became useful for you and understandable, for more on GraphQL, here are some great resources:

--

--

No responses yet