Giter Club home page Giter Club logo

Comments (2)

Mando75 avatar Mando75 commented on May 30, 2024

This lib is unopinionated about field resolvers. All it does is return back an object with all the requested relations/columns pre-loaded from the db. If you have a field resolver defined for one of those fields down the chain, your GraphQL server will still call that field resolver. If your GraphQL query includes a field that does not exist in your TypeORM entity, the loader will ignore it. If you never want to load a particular entity field from the db, you can tell the loader to ignore it (see below).

To help with resolving computed fields, it provides a decorator you can use on your entity fields to indicate whether a field is required. This way if you have a computed field on an entity, you can specify the loader include the dependent fields regardless of whether they were included in the query See the documentation for ignore and required here

@Entity()
class User extends BaseEntity {
  @LoaderConfiguration({ required: (context, fields) => fields.includes('fullName') })
  @Column()
  firstname: string;
  @LoaderConfiguration({ required: (context, fields) => fields.includes('fullName') })
  @Column()
  lastname: string;

  // computed method
  fullName() {
    return this.firstname + ' ' + this.lastname
  }
}

This lib does not help with the N+1 problem for fetching data from sources outside of TypeORM. For that, I suggest looking into the dataloader package on npm. It very easy to use this library in conjunction with dataloader if you so wish.

from typeorm-graphql-loader.

bombillazo avatar bombillazo commented on May 30, 2024

Thanks for the quick response and the thorough and informative answer! Appreciate it, this helps a lot! Don't know if you prefer to leave it open for reference.

from typeorm-graphql-loader.

Related Issues (16)

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.