Commit 3be6bc28 authored by Jure's avatar Jure

feat: use modelLoaders for model-specific loaders

parent c4c22552
Pipeline #13086 failed with stages
in 9 minutes and 50 seconds
......@@ -22,17 +22,22 @@ module.exports = () => {
const loaders = {}
components.forEach(component => {
if (component.model && component.modelName) {
if (component.model && component.modelName && component.modelLoaders) {
// Sets up the default loader, that gets model instances by id
// You can use it with e.g. context.loaders.User.load(id)
loaders[component.modelName] = defaultLoader(component.model)
Object.keys(component.modelLoaders).forEach(loaderName => {
loaders[component.modelName][loaderName] = new DataLoader(
component.modelLoaders[loaderName],
)
})
} else if (component.models) {
// If there are multiple models specified in a single component
// each can specify its own loaders
component.models.forEach(model => {
loaders[model.modelName] = defaultLoader(model.model)
if (model.loaders) {
Object.keys(model.loaders).forEach(loaderName => {
if (model.modelLoaders) {
Object.keys(model.modelLoaders).forEach(loaderName => {
loaders[model.modelName][loaderName] = new DataLoader(
model.loaders[loaderName],
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment