DEV Community

Cover image for GraphQL for beginners

GraphQL for beginners

Danijel Vincijanović on February 14, 2020

Whoo, already five years have passed since Facebook publicly released GraphQL in 2015. It's not anymore just a new shiny thing - GraphQL ecosystem ...
Collapse
 
ericathedev profile image
Erica Tanti

Very well explained and simple to understand 🛸 Especially loved the gifs! May I ask what you used to make them?

Collapse
 
davinc profile image
Danijel Vincijanović

Thanks a lot! 🙂 I was using PowerPoint! 😄 Recorded the presentation and converted video to the gif

Collapse
 
ericathedev profile image
Erica Tanti

Interesting, thank you, hadn't thought of that! The gifs look super smooth, nice one 😁

Collapse
 
pozda profile image
Ivan Pozderac

Great intro to the topic with cool examples, I like how you covered both frontend and backend so we know what is going on. Thanks on resources for further exploration, looking forward for more awesome articles from you! =D

Collapse
 
davinc profile image
Danijel Vincijanović

Thanks mate! 🤘

Collapse
 
firungumunene profile image
Francis Irungu Munene

Say I have a MSSQL/MySql/PostgreSQL database with two tables, to keep it simple, with say 10 and 20 fields respectively, I would have to write a separate resolver for all the 30 different fields? Can you show a simple example of such a use case?

Collapse
 
davinc profile image
Danijel Vincijanović • Edited

You don't have to write resolvers for each field. By default, if you didn't specify a resolver for a field, GraphQL will return an object property with the same name.

Imagine that you have "Spaceships" table with 30 fields. This will be our "main" resolver for querying all spaceships:

Query: {
    spaceships(obj, args, context, info) {
      return db.findAllSpaceships()
    }
}
Enter fullscreen mode Exit fullscreen mode

And now, because we didn't write resolvers for Spaceship fields, GraphQL will return spaceship.model if we queried model field, spaceship.weight for weight field and same applies for every other queryable field. Hope that this makes sense 🙂

Collapse
 
fagnerbrack profile image
Fagner Brack • Edited

what are key differences between GraphQL and, most commonly used, REST API architectural style

Comparing both with their differences makes no sense, see this for the details

A REST API Architectural style is not to make a GET request on a given end-point and is not commonly used in the wild except for the "text/html" media type.

Collapse
 
adrianbdesigns profile image
Adrian Bece

Very detailed post. Great work!

Tip: include a #beginner and/or #tutorial tags

Collapse
 
sunmik profile image
Sunmi

Informative article ! I just heard GraphQL from server engineer.

Collapse
 
squigglybob profile image
squigglybob

Thanks for the clear overview. I'm looking forward to getting into it with Gatsby...

Collapse
 
gsr7 profile image
gsr7

HI Danijel, Awesome explanation !! You make GraphQL easier for me...

Appreciated your effort and spending time to make this..

Collapse
 
guergana profile image
Guergana Tzatchkova

Best explanation I've seen so far. Thanks!

Collapse
 
charles1303 profile image
charles1303

Nice article. I have been using GraphQL for the above scenarios and I have not looked back since then 🙂.

Collapse
 
pfacklam profile image
Paul Facklam

Great introduction into the topic. Thank you @davinci2015

Collapse
 
oscarrodar profile image
Oscar Rodriguez

Thanks for the article.

Collapse
 
p3yman profile image
Peyman Eskandari

Great article with an interesting example 👍👏