Comments (2)
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.
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)
- Question : How can i use this loader without attaching GraphQLDatabaseLoader with predefined TypeOrm connection in GQL config? HOT 3
- export builder and other important types in the entry file please HOT 2
- Support for named columns HOT 4
- column "createdat" does not exist HOT 5
- use a related table for where() and order() HOT 12
- Thanks! HOT 1
- ConfigureLoader Not working! HOT 13
- Support Data Mapper entities HOT 1
- Ordering of sub relations
- Redundant typeof BaseEntity typing HOT 1
- How to properly implement resolvers? HOT 5
- Small fix for graphqlQueryBuilder.ts HOT 2
- Pagination query not selecting correct fields HOT 5
- Support nested/inherited types fields HOT 10
- Incorrect typing for `where` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typeorm-graphql-loader.