Using DataLoader to Avoid N+1 Queries in GraphQL

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

  • @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 8 місяців тому

    Good stuff

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

  • @rabbyhossain6150
    @rabbyhossain6150 2 роки тому

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

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

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

    You create terrific videos even stuff relative noob can understand.

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

  • @chongma
    @chongma 2 роки тому

    Thank you

  • @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 :) ua-cam.com/video/_HOp7hBEjp8/v-deo.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 🙏🏼🙏🏼

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

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

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

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

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

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

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

    thanks

  • @MoT-MasterOfThings
    @MoT-MasterOfThings 4 роки тому

    Why video quality is not higher than 360p

    • @leighhalliday
      @leighhalliday  4 роки тому +1

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