DEV Community

Cover image for Build API with GraphQL, Node.js, and Sequelize

Build API with GraphQL, Node.js, and Sequelize

Chinedu Orie on October 01, 2020

What is GraphQL? Unlike the traditional RESTFUL architecture where an endpoint returns a set of data designated by the API whether you w...
Collapse
 
uysim profile image
Uysim

I think you mean

npm install cors --save
Enter fullscreen mode Exit fullscreen mode

not

npm install core --save
Enter fullscreen mode Exit fullscreen mode
Collapse
 
nedsoft profile image
Chinedu Orie

That's correct, thanks

Collapse
 
didiamuri profile image
Didierson Amuri

Thank you so much, I spent a whole morning without finding a solution to the errors I had when trying to use GraphQL for my first time with MariaDB and Sequelize, you made it easy for me and I have now figured out how it works.
Congratulations!

Collapse
 
nedsoft profile image
Chinedu Orie

Glad to learn that you found it helpful!

Collapse
 
umakantv profile image
Umakant Vashishtha • Edited

Great Article!
I noticed that using post.getAuthor() and post.getComments() we tell graphql to query database for all the posts one by one.
And I know this is only a template, but one wouldn't want to have as many queries to their DB. So I used sequelize' include model operation and then simply just returned post.author and post.comments. Of course this also comes at a cost of joining tables but sql table joins are better than multiple DB calls. Hope this would help someone.
Also, I would create a PR if you want :)

Collapse
 
ishwarjha profile image
Ishwar Jha

Hey, I am getting the error
Loaded configuration file "database/config/config.js".
Using environment "development".

ERROR: Error parsing url: undefined
When I am trying to use your tutorial with MySQL. Can you guide?

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

define the database url or IP and it will be fine

Collapse
 
ilhamalamsyh profile image
Ilham Alamsyah • Edited

set the use_env_variable: process.env.DEV_DATABASE_URL on file "database/config/config.js"

it has worked on me

Collapse
 
oluwasetemi profile image
Ojo Oluwasetemi

Great. Work in here

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

Cheers man. That's great! I would even use it as template for a quick project i want to do, can you please provide the source code / (github / gitlab repo)? that would be nice! :)

Collapse
 
edwardzzz profile image
Zach • Edited

what is mytoken and how do you implement it? would be useful to readers. not a very good explanation as you have it currently. inside graphql when i run the register mutation all i get is "null"

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

you can use simple jwt library to handle token pretty easily