GraphQL vs REST for Side Projects

Поділитися
Вставка
  • Опубліковано 5 вер 2024
  • 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 роки тому +32

    I would really. love a tutorial video on automatically generating the queries with the react hooks. Awesome video!

  • @alkismavridis1
    @alkismavridis1 5 років тому +9

    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 років тому +3

      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 років тому +2

      ​@@bawad I see. What do you think that would be different/less complex in the rest version?

    • @bawad
      @bawad  5 років тому +2

      making the routes efficient

    • @alkismavridis1
      @alkismavridis1 5 років тому +3

      @@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 роки тому +5

      @@alkismavridis1 nope lol

  • @lancerhu8107
    @lancerhu8107 3 роки тому +42

    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 роки тому +7

      @@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.

  • @imtheaman
    @imtheaman 3 роки тому +1

    Best channel i've ever found on youtube until now.

  • @MayronWoW
    @MayronWoW 3 роки тому +1

    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.

  • @jessewright870
    @jessewright870 5 років тому +6

    Exactly the question in my mind recently

  • @bobbyshaftoe
    @bobbyshaftoe 3 роки тому +1

    Damn. Best GraphQL overview I have seen on UA-cam. Great job!

  • @aashayamballi
    @aashayamballi 5 років тому +6

    Thanks Ben for sharing this valuable information 😊

  • @Kats0unam1
    @Kats0unam1 Рік тому

    I like the integration of GraphQL with Nest.

  • @AbdullahEAk
    @AbdullahEAk 5 років тому +3

    Bro you are always on point, I love it. Keep up the good work

  • @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.

  • @vitaliikravets2777
    @vitaliikravets2777 3 роки тому +4

    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?

  • @ChumX100
    @ChumX100 3 роки тому +14

    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?

  • @iykazorji8171
    @iykazorji8171 5 років тому +1

    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...

  • @user-qp7kb7yw8y
    @user-qp7kb7yw8y 5 років тому +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 років тому +29

      I want to try monetizing them so I'm not going to open source it at this time

  • @StephenRayner
    @StephenRayner 5 років тому

    Cheers man, these videos are absolutely fantastic

  • @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.

  • @IhiItsMEMaRiO
    @IhiItsMEMaRiO 5 років тому +41

    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.

  • @piby1802
    @piby1802 4 роки тому +3

    I tried graphql but switched back to django because of several reasons like pagination, rate limiting, caching, authentication, authorization etc

    • @migueldomingos4570
      @migueldomingos4570 4 роки тому +2

      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 роки тому +1

      @@piby1802 ah! ok! I wasnt aware graphql had such enourmous disanvanatges

  • @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

  • @MechanicalMooCow
    @MechanicalMooCow 2 роки тому +1

    2:15 - you either do or you don't, except when you're unsure; then you doon't.

  • @BrandonSWie
    @BrandonSWie 4 роки тому

    Thanks for info as always.

  • @medilies
    @medilies Рік тому

    I like the thumbnail XD

  • @hipdev_
    @hipdev_ 5 років тому

    Thanks as always Ben :)

  • @khatuntsovmikhail6223
    @khatuntsovmikhail6223 5 років тому +4

    How do you addressing breaking changes such as removing fields?

    • @bawad
      @bawad  5 років тому +6

      By not removing fields for a long time

    • @Eckster
      @Eckster 3 роки тому +2

      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.

  • @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...

  • @ineris28
    @ineris28 5 років тому

    Great! Thanks for sharing!

  • @jakobankarhem6281
    @jakobankarhem6281 4 роки тому +2

    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

  • @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?

  • @PrashanthKrishnamurthy
    @PrashanthKrishnamurthy 5 років тому +1

    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 років тому +2

      I run middleware before resolvers for that, works pretty well

  • @Mem0ryFade
    @Mem0ryFade 3 роки тому +1

    If you want that tooling but for REST you can get similar productivity levels in Rails.

  • @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 🤔

  • @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 роки тому +1

    in your udemy course you should add Spanish subtitles to your course

  • @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 ?

  • @bill.j.pearce
    @bill.j.pearce 3 роки тому

    graphql-ruby is fantastic just btw, the Ruby on Rails comment is very much outdated.

  • @DanteS7
    @DanteS7 5 років тому +1

    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.

  • @shadow16810
    @shadow16810 4 роки тому +3

    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 роки тому +1

      nope, from what I've seen NestJS is not opinionated when it comes to the db

    • @danbo967
      @danbo967 4 роки тому

      @@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.

  • @makisetakashi
    @makisetakashi 5 років тому +3

    redis is not hard to implement, that easy to implement redis in your graphql server

  • @BenHayat
    @BenHayat 3 роки тому

    @Ben Awad;
    Not only you have a great first name, I like your last name too... :-)

  • @Thecoolbigbear
    @Thecoolbigbear 3 роки тому

    Young Ben Awad before his unicorn company took off

  • @natqe4049
    @natqe4049 5 років тому

    For a big projects is a pain in the ass

  • @florianrubel6318
    @florianrubel6318 5 років тому +1

    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 років тому +2

      You get rid of the deprecated fields later on, just not immediately

  • @jorgevilasboas
    @jorgevilasboas 5 років тому +1

    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 років тому +1

      take a look at any of my playlists ua-cam.com/play/PLN3n1USn4xlma1bBu3Tloe4NyYn9Ko8Gs.html

  • @matthewzecchini9951
    @matthewzecchini9951 5 років тому

    Hey random question. How many frontend developers should there be per backend? What ratio is normal?

    • @bawad
      @bawad  5 років тому +1

      I'm not sure

  • @chimerablack4913
    @chimerablack4913 5 років тому +3

    why is web so harrrd

  • @danieldosen5260
    @danieldosen5260 4 роки тому

    IMO - any new app - go with graphql... and app already using rest - don't 'rip and replace'

  • @codebreatherHQ
    @codebreatherHQ 5 років тому +9

    Check out swaggerdoc for rest api

    • @iancuvlad7368
      @iancuvlad7368 3 роки тому

      Swagger is just scotch over window

  • @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

  • @DanteS7
    @DanteS7 5 років тому

    Ben have you tried Vulcan.js?

    • @bawad
      @bawad  5 років тому

      nope

  • @aleksd286
    @aleksd286 5 років тому +1

    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

  • @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.

  • @honglytech
    @honglytech 5 років тому

    It's like he is whispering to the mic...

  • @chimerablack4913
    @chimerablack4913 5 років тому

    oh, no django? too bad, I love django

  • @natqe4049
    @natqe4049 5 років тому +3

    Graphql is so wrong

    • @cyrax5628
      @cyrax5628 5 років тому +3

      Why is that?

    • @nubl3718
      @nubl3718 5 років тому +8

      ooh look at me I'm so edgy