Using DataLoader to Avoid N+1 Queries in GraphQL

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 พ.ย. 2024

ความคิดเห็น • 41

  • @melpacheco9288
    @melpacheco9288 4 ปีที่แล้ว +3

    I love this channel, always practical examples.

    • @leighhalliday
      @leighhalliday  4 ปีที่แล้ว

      Thanks, Mel :) I appreciate it. N+1 in GraphQL can kill your performance like nothing else!

  • @larube
    @larube 4 ปีที่แล้ว

    Looks good to work with early 2000's hardcore albums !

    • @leighhalliday
      @leighhalliday  4 ปีที่แล้ว

      Nothing is better for coding!

    • @larube
      @larube 4 ปีที่แล้ว

      ​@@leighhalliday That's right !

  • @VincentFulco
    @VincentFulco 4 ปีที่แล้ว

    You create terrific videos even stuff relative noob can understand.

    • @leighhalliday
      @leighhalliday  4 ปีที่แล้ว

      Thanks, Vincent! That's my goal :D

  • @rabbyhossain6150
    @rabbyhossain6150 2 ปีที่แล้ว

    Suppose, I want to display two artist names for each album and for this what should be the query?

  • @melpacheco9288
    @melpacheco9288 4 ปีที่แล้ว +2

    Hey man, did you ever do the video loading multiple records?

    • @leighhalliday
      @leighhalliday  4 ปีที่แล้ว +1

      Hehe... no I didn't :D I actually wrote an article about it using Ruby on Rails pganalyze.com/blog/efficient-graphql-queries-in-ruby-on-rails-and-postgres but the truth is that I don't maintain any sort of production node based GraphQL API, so I haven't been deep into this stuff. My apologies!

    • @melpacheco9288
      @melpacheco9288 4 ปีที่แล้ว

      @@leighhalliday no worries, your content is always relevant, and you always use great examples. looking forward to the next video!

  • @PatrikRasch
    @PatrikRasch 11 หลายเดือนก่อน

    Good stuff

  • @ogbillity
    @ogbillity 3 ปีที่แล้ว

    Hello, Leigh thank you for this tutorial. How do pass user alongside the loader in the context. I am trying to handle authentication and authorization.

    • @leighhalliday
      @leighhalliday  3 ปีที่แล้ว

      Hey Peter! I believe you'd have to load the user within the context function here: github.com/leighhalliday/nextjs-graphql-example/blob/dataloader/pages/api/graphql.js#L112

  • @arobmusicful
    @arobmusicful 4 ปีที่แล้ว

    Comeback Kid!! Hell yeah!

    • @leighhalliday
      @leighhalliday  4 ปีที่แล้ว +1

      Wake the silence, wake the dead!

    • @arobmusicful
      @arobmusicful 4 ปีที่แล้ว

      Great video! Nice to see a thorough explanation of this issue and a bonus to see another dev down with the core!! (I come from that scene and have been getting into development over the past year, so this is the best of both worlds! Lol)

  • @sebastian5100630
    @sebastian5100630 3 ปีที่แล้ว

    Hello Leigh i have a ques, if i have a type like this
    type Order {
    total
    qtity
    createdAt
    user {
    id
    name
    }
    client {
    id
    name
    }
    }
    this single loader still work?

    • @leighhalliday
      @leighhalliday  3 ปีที่แล้ว

      You would use a User loader and a Client loader

  • @Rimteh33
    @Rimteh33 4 ปีที่แล้ว

    Hey Leigh, could you help me out to solve this issue using nexus for schema definitions?

    • @leighhalliday
      @leighhalliday  4 ปีที่แล้ว

      Hey Aleksej! I'd love to but I honestly am so strapped for time I don't think I can look into this... barely holding on as is.

    • @Rimteh33
      @Rimteh33 4 ปีที่แล้ว

      @@leighhalliday I totally understand. Do you have some useful references?

  • @chongma
    @chongma 2 ปีที่แล้ว

    Thank you

    • @leighhalliday
      @leighhalliday  2 ปีที่แล้ว

      Glad you enjoyed it Matthew!

  • @AliYasir5247
    @AliYasir5247 4 ปีที่แล้ว

    in the video its mentioned more advance dataloader usecases?

    • @leighhalliday
      @leighhalliday  4 ปีที่แล้ว

      Coming at some point in the future :D I want to cover the topics I covered in my article here, but do them in Node (article is about Ruby on Rails). pganalyze.com/blog/efficient-graphql-queries-in-ruby-on-rails-and-postgres

  • @erenkarahasan6834
    @erenkarahasan6834 3 ปีที่แล้ว

    Thanks for the insightful video
    Where is the link mentioned at 3:19 tho? :)

    • @leighhalliday
      @leighhalliday  3 ปีที่แล้ว +1

      Haha... I honestly have no idea. Here's one that may help though :) th-cam.com/video/_HOp7hBEjp8/w-d-xo.html

  • @behindthescenex
    @behindthescenex 4 ปีที่แล้ว

    Hi leigh thank you so much for the lesson! 😭🙏🏼 I want to ask, if i want to load 100 records in a single request, is it possible to cache them when using dataloader ?

    • @leighhalliday
      @leighhalliday  4 ปีที่แล้ว +1

      Thanks, Gede! What do you mean cache them? So that on the following API request DataLoader doesn't have to fetch a record it has already loaded? I suppose it is... but you'd have to save it somewhere, right? If you save it in memory, you'd want to make sure that it doesn't bloat too much, if you save it in Redis, you'd be required to do 1 request to Redis then 1 request to Postgres to fetch remaining... so you may find it's just easier to avoid thinking about caching until it becomes an issue.

    • @behindthescenex
      @behindthescenex 4 ปีที่แล้ว

      @@leighhalliday Yes thats the idea, i dont have to re-fetch the data again if i already load it once. Thank you so much for the tip leigh. I'll try your redis suggestion. This tutorial helped me a lot on my final exam 🙏🏼🙏🏼

  • @pyfreelancer5527
    @pyfreelancer5527 3 ปีที่แล้ว

    thanks

  • @MoT-MasterOfThings
    @MoT-MasterOfThings 4 ปีที่แล้ว

    Why video quality is not higher than 360p

    • @leighhalliday
      @leighhalliday  4 ปีที่แล้ว +1

      TH-cam is still processing the HD versions... just finished uploading. They publish SD first and then HD when it's ready. Wait like 30 minutes and it should be good.

    • @dru284
      @dru284 4 ปีที่แล้ว +1

      Great work Leigh!

    • @leighhalliday
      @leighhalliday  4 ปีที่แล้ว +1

      Thanks Andrew!

  • @PavanMehta
    @PavanMehta 3 ปีที่แล้ว

    It's from facebook indeed!

  • @jeresalem
    @jeresalem 4 ปีที่แล้ว

    Or just use Hasura ☺️

    • @leighhalliday
      @leighhalliday  4 ปีที่แล้ว +1

      I've been meaning to try that out! Looks really cool.