GraphQL vs REST for Side Projects

  Рет қаралды 91,408

Ben Awad

Ben Awad

Күн бұрын

I go over the pros and cons of GraphQL vs REST that I experienced from creating 2 side projects with GraphQL.
#graphql

----
Follow me online: voidpet.com/be...
#benawad

Пікірлер: 99
@maarten1012TTT
@maarten1012TTT 4 жыл бұрын
I would really. love a tutorial video on automatically generating the queries with the react hooks. Awesome video!
@alkismavridis1
@alkismavridis1 5 жыл бұрын
Great video! Thanks! Stangely, I personally felt that moving to graphQL speed up my backend efficiency (I have a spring boot server and used graphql-java-tools library which is GREAT). My way of dealing with DB communication in graphQL is to follow exactly the same logic as I would in the rest version. Lets assume that we have a teacher entity that has relationship to many student entities. My REST api would work like that: 1. I have a quick rest controller that fetches the teachers without their students (no sql JOINS). 2. I have a less quick rest controller that fetches the teachers, but also performs the sql JOINS to include their students. 3. In the end of the day, my frontend would decide which URL to call, according to whether it needs the student lists or not. So my graphQL version would follow the same logic. Simply I would have 2 resolvers instead of 2 rest controllers. My DB queries would be exactly the same, and my frontend would decide which of those 2 it needs, exactly like the rest version.
@bawad
@bawad 5 жыл бұрын
I agree and that's nice, but to do that properly (or efficiently) in graphql where you only join on some queries is more complex
@alkismavridis1
@alkismavridis1 5 жыл бұрын
​@@bawad I see. What do you think that would be different/less complex in the rest version?
@bawad
@bawad 5 жыл бұрын
making the routes efficient
@alkismavridis1
@alkismavridis1 5 жыл бұрын
@@bawad can you explain what you mean by that? Maybe provide an example that would be simpler in a rest implementation than in a graphQL implementation, and show the difference?
@christiancole6692
@christiancole6692 2 жыл бұрын
@@alkismavridis1 nope lol
@imtheaman
@imtheaman 3 жыл бұрын
Best channel i've ever found on youtube until now.
@lancerhu8107
@lancerhu8107 3 жыл бұрын
You don't need to change REST version if you are adding field either.
@JustPlayerDE
@JustPlayerDE 2 жыл бұрын
but if you change what it returns
@Siddiskongen
@Siddiskongen 2 жыл бұрын
@@JustPlayerDE No. As long as you add fields you are not breaking the contract. Are you changing (e.g renaming / chaning types) or removing fields in either rest or graphql you are breaking the contract. In both instances you can deprecate the fields instead of removing them and let the consumers update the requests.
@bobbyshaftoe
@bobbyshaftoe 3 жыл бұрын
Damn. Best GraphQL overview I have seen on KZfaq. Great job!
@jessewright870
@jessewright870 5 жыл бұрын
Exactly the question in my mind recently
@MayronDev
@MayronDev 3 жыл бұрын
Exact same conclusion I came to. It's a pain on the backend using dataloaders with a database not tried and tested with graphql and finding your own solutions. But using graphql on the frontend is amazing.
@AbdullahEAk
@AbdullahEAk 5 жыл бұрын
Bro you are always on point, I love it. Keep up the good work
@aashayamballi
@aashayamballi 5 жыл бұрын
Thanks Ben for sharing this valuable information 😊
@Kats0unam1
@Kats0unam1 Жыл бұрын
I like the integration of GraphQL with Nest.
@faridguzman91
@faridguzman91 2 жыл бұрын
Thanks man, was offered a gql, redux-saga ,apollo, react fullstack dev contract, but now i see what i have to deal with if i take the job.
@iykazorji8171
@iykazorji8171 5 жыл бұрын
I think this is absolutely spot on again! I recently built a test project with Graphcool and Apollo on the frontend and it was an amazing experience. But although setting up an actual graphql server is quite a chore I think the payoff on the long run is worth it...
@StephenRayner
@StephenRayner 5 жыл бұрын
Cheers man, these videos are absolutely fantastic
@ChumX100
@ChumX100 3 жыл бұрын
GraphQL seems to be most effective for organizations of multiple dev teams that are mostly independent (Facebook). When you are the sole consumer of your own API, you pretty much know what data you want and how you want it, so you can set up endpoints tailored to your necessities. Also, isn't simple validation a form of type system?
@IhiItsMEMaRiO
@IhiItsMEMaRiO 5 жыл бұрын
i miss the projet videos ;(
@riongull
@riongull 5 жыл бұрын
Agreed. My vote is a Nexus 2 backend serving a Gatsby front end that uses `gatsby-browser` to show dynamic (frequently changing) data in a rehydrated React front end.
@vitaliikravets2777
@vitaliikravets2777 3 жыл бұрын
About no need for GraphQL versions. Extending schema example that you provided would work with REST most of the times too, because it is backward compatible. How do you deal with backward incompatible changes, like removing or renaming a field/entity?
@user-qp7kb7yw8y
@user-qp7kb7yw8y 5 жыл бұрын
Ben, may you please open source your 2 side projects. It would be very awesome to see the actual code of such awesome stuff. Cheers.
@bawad
@bawad 5 жыл бұрын
I want to try monetizing them so I'm not going to open source it at this time
@medilies
@medilies Жыл бұрын
I like the thumbnail XD
@BrandonSWie
@BrandonSWie 4 жыл бұрын
Thanks for info as always.
@hipdev_
@hipdev_ 5 жыл бұрын
Thanks as always Ben :)
@JoseHenrique-xg1lp
@JoseHenrique-xg1lp 2 жыл бұрын
I'm going to give this a try. I've been working with ERPs for a very long time and thanks to questionable design, I've caught SQL tables with over 70 columns and tens of thousands of rows.... It's a pain to deal with under / over fetching for table display and report exporting.
@ineris28
@ineris28 4 жыл бұрын
Great! Thanks for sharing!
@MechanicalMooCow
@MechanicalMooCow 2 жыл бұрын
2:15 - you either do or you don't, except when you're unsure; then you doon't.
@lmfao7224
@lmfao7224 5 жыл бұрын
I don’t really like mutations but queries are good. GraphQL works best in a full stack JS environment. If you’re working outside of that it can be a pain with such a rigid type structure (say a Rails GraphQL API and a native iOS App) they don’t play nearly as nicely and a MERN stack app
@piby1802
@piby1802 4 жыл бұрын
I tried graphql but switched back to django because of several reasons like pagination, rate limiting, caching, authentication, authorization etc
@migueldomingos4570
@migueldomingos4570 4 жыл бұрын
Graphql and django are perfectly compatible One is a way to define an api and another is backend framework
@piby1802
@piby1802 4 жыл бұрын
@@migueldomingos4570 Sorry I meant to say django rest framework
@migueldomingos4570
@migueldomingos4570 4 жыл бұрын
@@piby1802 ah! ok! I wasnt aware graphql had such enourmous disanvanatges
@Mem0ryFade
@Mem0ryFade 3 жыл бұрын
If you want that tooling but for REST you can get similar productivity levels in Rails.
@jakobankarhem6281
@jakobankarhem6281 4 жыл бұрын
Hey, I think you would be interested in restful-react. It has some of the functionality that you mention liking about graphql with apollo
@bawad
@bawad 4 жыл бұрын
good to know, thanks
@geekboy328
@geekboy328 4 жыл бұрын
IMO you don’t need a thick client or API. You can do all of it using good old fashioned server rendered templates. It will be far more performant than any SPA + API combo (especially when it comes to bundle size and TTI). If you’re a frontend dev who doesn’t know backend templating and you NEED react, use Nextjs static export and then do a fully serverless backend. All the other approaches give you the worst of both old style web pages and SPA’s...
@khatuntsovmikhail6223
@khatuntsovmikhail6223 5 жыл бұрын
How do you addressing breaking changes such as removing fields?
@bawad
@bawad 5 жыл бұрын
By not removing fields for a long time
@Eckster
@Eckster 3 жыл бұрын
We would have clients send a version number with each request, and we would deprecate fields, but continue supporting them. After a couple months, when we figured almost all clients had updated to using the non-deprecated fields, we would bump the lowest API version we supported, and clients that sent the older version would be redirected to update. That being said, this doesn't work great if other people are developing clients for your API.
@Kay8B
@Kay8B 3 жыл бұрын
For the over/under fetching I remember designing a method where you input the fields you needed and only those would be selected from the database as opposed to select * : which gave me a similar effect but nice to know QL has it out the box
@mariobisignani4477
@mariobisignani4477 2 жыл бұрын
Not a very good idea to build such system by yourself, you risk to introduce many security problems. For instance now did you handle sql injection?
@randycanela1818
@randycanela1818 4 жыл бұрын
in your udemy course you should add Spanish subtitles to your course
@aaronbaron6468
@aaronbaron6468 2 жыл бұрын
I remember almost 10 months ago I chose gql for my personal full stack project for my resume to host on heroku to land a dev job, I read these advantages and thought maybe it'll be better since heroku free tier is slow as shit anyway so I made the gql choice
@seamini9172
@seamini9172 2 жыл бұрын
Did you end up landing a job and did learning graphql help?
@Thecoolbigbear
@Thecoolbigbear 3 жыл бұрын
Young Ben Awad before his unicorn company took off
@PrashanthKrishnamurthy
@PrashanthKrishnamurthy 5 жыл бұрын
Controlling fields based on roles is a big problem in GraphQL - so much so that I reverted to Rest / ORM based ad-hoc query languages to avoid dealing with the potential security issues. Am I missing any tooling that could have made my life easier (other than doing DB-based auth in Hasura / PostGraphile etc.)
@bawad
@bawad 5 жыл бұрын
I run middleware before resolvers for that, works pretty well
@bill.j.pearce
@bill.j.pearce 3 жыл бұрын
graphql-ruby is fantastic just btw, the Ruby on Rails comment is very much outdated.
@shaunpx1
@shaunpx1 2 жыл бұрын
I've been looking all over the web and have failed to see how Graphql is secure compared to an API services that accesses the db and acts a secure bridge between data and the client 🤔
@makisetakashi
@makisetakashi 5 жыл бұрын
redis is not hard to implement, that easy to implement redis in your graphql server
@natqe4049
@natqe4049 5 жыл бұрын
For a big projects is a pain in the ass
@codebreatherHQ
@codebreatherHQ 5 жыл бұрын
Check out swaggerdoc for rest api
@iancuvlad7368
@iancuvlad7368 3 жыл бұрын
Swagger is just scotch over window
@DanteS7
@DanteS7 5 жыл бұрын
Also, what would you use (prisma, hasura, etc.) if you were starting a new project today?
@bawad
@bawad 5 жыл бұрын
I would use typeorm today
@approots
@approots 5 жыл бұрын
If you are using Postgres, Hasura is fantastic.
@BenHayat
@BenHayat 3 жыл бұрын
@Ben Awad; Not only you have a great first name, I like your last name too... :-)
@shadow16810
@shadow16810 4 жыл бұрын
Would you say NestJS helps in the "no Ruby on Rails/Django yet" point? From my experience using Nest it really looked like and awesome Framework to build graphQL APIs
@bawad
@bawad 4 жыл бұрын
nope, from what I've seen NestJS is not opinionated when it comes to the db
@danbo967
@danbo967 3 жыл бұрын
@@bawad Hi, what about nexus ? I saw the prisma team abandoned the GraphQL-yoga project to collaborate with nexus. I think GraphQL-yoga was pretty neat. Maybe nexus can become even better.
@valour.se47
@valour.se47 5 жыл бұрын
Can't we , instead of writing resolver for each field why not write resolver for each resource, also can't we rate limit the endpoint , ultimately whoever is going to call any query it is going to be a http call so we can block it right away there on the server side ?. what do you think ?
@jorgevilasboas
@jorgevilasboas 5 жыл бұрын
Hi Ben! Any code generator or template for a project made with graphql, node, mongo and react native?
@bawad
@bawad 5 жыл бұрын
I don't I'm on graphql/node/postgresql/react-native
@jorgevilasboas
@jorgevilasboas 5 жыл бұрын
@@bawad Could you share It, please?
@bawad
@bawad 5 жыл бұрын
take a look at any of my playlists kzfaq.info/sun/PLN3n1USn4xlma1bBu3Tloe4NyYn9Ko8Gs
@chimerablack4913
@chimerablack4913 5 жыл бұрын
why is web so harrrd
@florianrubel6318
@florianrubel6318 5 жыл бұрын
I don't think, that just adding new fields is a good idea. It will mess the project. Keep code clean and get rid of the deprecated stuff. A client side handling could be better.
@bawad
@bawad 5 жыл бұрын
You get rid of the deprecated fields later on, just not immediately
@matthewzecchini9951
@matthewzecchini9951 5 жыл бұрын
Hey random question. How many frontend developers should there be per backend? What ratio is normal?
@bawad
@bawad 5 жыл бұрын
I'm not sure
@danieldosen5260
@danieldosen5260 4 жыл бұрын
IMO - any new app - go with graphql... and app already using rest - don't 'rip and replace'
@DanteS7
@DanteS7 5 жыл бұрын
Ben have you tried Vulcan.js?
@bawad
@bawad 5 жыл бұрын
nope
@FellTheSky
@FellTheSky 2 жыл бұрын
I'm investigating a bit but honestly it looks like a waste of time. I rather learn AWS and if some day I get a assign some task of graphql I'll learn it there. It looks so much work for very little reward, unless you're facebook I guess
@aleksd286
@aleksd286 5 жыл бұрын
Queries sure look nice. Because at the moment my FE be like yield call(messages.find, { query: { $limit: limit, chat_id: id, $sort: { created_at: -1 } } }); While the NodeJS BE has like 50 line long sequelize query for the call above... Wtf? :D
@jakubsurdej4339
@jakubsurdej4339 5 жыл бұрын
I developed application using graphql-ruby few months ago, so "There's no Ruby on Rails" is just a lie
@bawad
@bawad 5 жыл бұрын
I guess I meant there's not a framework that's as complete as Ruby on Rails that treats GraphQL as a first class citizen
@jakubsurdej4339
@jakubsurdej4339 5 жыл бұрын
@@bawad graphql-ruby appends RoR functionality, so you can just use RoR for graphql. Also, there are few startups using this gem, so there should not be a bigger problems with creating 'real' apps
@honglytech
@honglytech 5 жыл бұрын
It's like he is whispering to the mic...
@chimerablack4913
@chimerablack4913 5 жыл бұрын
oh, no django? too bad, I love django
@burhanbudak6041
@burhanbudak6041 2 жыл бұрын
GraphQL sucks. There is to many tools and the tutorial don't follow the thin red line. It forced typescript even if its not enabled. It makes me like PHP which means something.
@natqe4049
@natqe4049 5 жыл бұрын
Graphql is so wrong
@cyrax5628
@cyrax5628 5 жыл бұрын
Why is that?
@nubl3718
@nubl3718 5 жыл бұрын
ooh look at me I'm so edgy
Guide to the GraphQL Ecosystem
19:47
Ben Awad
Рет қаралды 60 М.
The Truth About GraphQL
12:06
Theo - t3․gg
Рет қаралды 97 М.
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 36 МЛН
Идеально повторил? Хотите вторую часть?
00:13
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 18 МЛН
小蚂蚁被感动了!火影忍者 #佐助 #家庭
00:54
火影忍者一家
Рет қаралды 55 МЛН
A teacher captured the cutest moment at the nursery #shorts
00:33
Fabiosa Stories
Рет қаралды 63 МЛН
GraphQL vs REST: What's The Difference And When To Use Which?
26:57
GraphQL N+1 Problem
16:14
Ben Awad
Рет қаралды 109 М.
7 Amazing Developer Tools that you're not using yet
6:27
Fireship
Рет қаралды 1,9 МЛН
GraphQL vs REST: Which is Better for APIs?
7:31
IBM Technology
Рет қаралды 195 М.
REST vs. GraphQL: Critical Look
33:06
Nordic APIs
Рет қаралды 61 М.
Where to Host a Fullstack Project on a Budget
21:44
Ben Awad
Рет қаралды 334 М.
My GraphQL Performance Problem
13:33
Ben Awad
Рет қаралды 49 М.
Stop Making These 5 GraphQL Mistakes
8:59
TomDoesTech
Рет қаралды 2,8 М.
Is tRPC The End Of REST/GraphQL?
13:48
Web Dev Simplified
Рет қаралды 135 М.
My Thoughts on Apollo Federation for GraphQL Microservices
10:58
Как настроить камеру хоп-ап
1:00
TimToker
Рет қаралды 2,2 МЛН
NFC и аксессуары для CMF Phone 1
0:49
Rozetked
Рет қаралды 282 М.
phone for yourself 📱#shorts
0:17
RELAXING DAILY
Рет қаралды 4,6 МЛН
САМЫЙ КРЕПКИЙ ТЕЛЕФОН #shorts
0:27
Паша Осадчий
Рет қаралды 1,5 МЛН