graphql-mongo-helpers icon indicating copy to clipboard operation
graphql-mongo-helpers copied to clipboard

Suggestion: new "API" to `createLoader`

Open noghartt opened this issue 2 years ago • 3 comments

Suggestion

Instead of using just only one argument as an object with named properties, could be interesting to turn it in more arguments with something like: createLoader(model, loaderName, options).

IMO, with it, can be separated the concern by domains, the required args: model and loaderName, and the options as an optional argument with default values.

Code Example

// Maybe in `loaderName` could be transform User to `UserLoader` under the hood
createLoader(UserModel, 'User', {
  viewerCanSee = defaultViewerCanSee,
  filterMapping = {},
  isAggregate = false,
  shouldValidateContextUser = false,
  defaultFilters = {},
  defaultConditions = {},
  defaultSort = { createdAt: -1 },
});

noghartt avatar Dec 17 '21 04:12 noghartt

I like this.

Tsugami avatar Dec 17 '21 04:12 Tsugami

feel free to do a poc and send a pr, but this will be a bigger breaking change

daniloab avatar Dec 17 '21 12:12 daniloab

IMO, with it, can be separated the concern by domains, the required args: model and loaderName, and the options as an optional argument with default values.

Yes! It would be a bigger breaking change (probably some major update). I'll try to do POC to implement this (and some other things).

noghartt avatar Dec 17 '21 13:12 noghartt