DEV Community

Cover image for What is GraphQL and how to use it

What is GraphQL and how to use it

Aditya Sridhar on December 23, 2018

This post was originally published in adityasridhar.com What is GraphQL? It is basically a query language for API's GraphQL shows what...
Collapse
 
davidisrawi profile image
David Israwi

Thanks for the tutorial Aditya!

Question: When does the resolve for movies get executed for a directorType? Does it run the function every time you call for a director, or does this code run beforehand and is cached in case the user makes a call for a director's movies?

Thanks!

Collapse
 
adityasridhar profile image
Aditya Sridhar

That's a really good question.

It would run every time you call for a director. And in a Real application that resolve function may end up calling a DB or making a HTTP request.

To make this more efficient a cache could be implemented so that the DB or HTTP call can be avoided whenever possible. But the cache implementation would be specific to your application.

Collapse
 
10secondsofcode profile image
Elango Sundar • Edited

@aditya Nice Tutorials. First time understand the graphql concepts clearly. Thanks.

Collapse
 
cepheivv profile image
cepheiVV

In this tutorial you're testing the input/output by the Graphiql web UI.
How would I make the request from within the code, instead of the UI?

Collapse
 
adityasridhar profile image
Aditya Sridhar

You could send a HTTP POST request to the graphql server. For example using curl you can call the hello endpoint as follows

curl -X POST -H "Content-Type: application/json" -d "{\"query\": \"{ hello }\"}" http://localhost:5000/graphql

You can checkout the following url to know more about accessing the graphql endpoints from a client.

graphql.org/graphql-js/graphql-cli...

Collapse
 
aexol profile image
Artur Czemiel

I recommend learning with visual editor here:

graphqleditor.com/

Collapse
 
adityasridhar profile image
Aditya Sridhar

Thanks for sharing this. Pretty helpful

Collapse
 
vitor9 profile image
Vitor Souza

Thanks alot for the tutorial!
It was a really nice introduction to GraphQL, great work.

Collapse
 
alexvirtualbr profile image
Alexandre Ferreira

Ooooh, great tuto Aditya!!!

Simple and direct. Now I'm ready to learn more about GraphQL.

Thanks.

Collapse
 
adityasridhar profile image
Aditya Sridhar

Thank you. Glad it helped.