Code Monkey home page Code Monkey logo

Comments (4)

B4nan avatar B4nan commented on September 26, 2024

dataloaders dont work on em.find at all, they are only for reference and collection loading.

not sure how that could be combined with nest, any ideas @darkbasic?

edit: I guess something like this should work:

  @ResolveField(() => User)
  public async author(@Parent() book: Book) {
    return book.author.load();
  }

note that you need to use the Reference wrapper for your relation:

@ManyToOne(() => User, { ref: true })
public author: Ref<User> // Ref, not Rel

edit 2: moving back to the main repo, as the dataloader docs would indeed deserve more details about this

from mikro-orm.

B4nan avatar B4nan commented on September 26, 2024

Btw there is apparently one alternative if you dont want to use the Ref wrapper - you can create it via wrap helper dynamically and return that from your resolver:

  @ResolveField(() => User)
  public async author(@Parent() book: Book) {
    return wrap(book.author).toReference().load();
  }

(at least that's what one user recently said worked for them)

I would still rather suggest using it - type safe relations (Loaded type) depend on this too.

from mikro-orm.

ceopaludetto avatar ceopaludetto commented on September 26, 2024

Thank you for the quick response, I've tried here and just works!

from mikro-orm.

B4nan avatar B4nan commented on September 26, 2024

hope this makes it clearer, PR welcome if you see more room for improvements

from mikro-orm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.