49 karma · joined May 25, 2022 (4y ago) · 34 submissions
comment 4y ago · link · parent
I agree there will have been lots of progress. However, 30 years from now people will probably say that the same thing to excuse todays predictions if they were wrong.
comment 4y ago · link · parent
sorry about that
comment 4y ago · link · parent
Edit: I've found this consistently building multiple data processing applications over multiple years and multiple companies
comment 4y ago · link · parent
Sounds like it's inferior to manually using a DataLoader within every resolver that fetches an object.
eg project has a client. In the resolver for a projects client, you fetch the client from DB. With DataLoader you manually cache the request for the client. With in-built caching you must resolve the client for the server to know the ID, and then on next resolve of the client, after fetching, it matches the ID and doesn't have to resolve it's fields again, but it still had to fetch both times?
comment 4y ago · link · parent
> type GetProject = (...) => ... > type ProjectCRUD = { get: GetProject, set: ... }
> constructor(private projectCrud: ProjectCrud)
Yep that is a more concise way of doing the same thing. I've considered that approach and it seems perfectly reasonable, even cleaner. The only reason I haven't is because constructors offer a more standardised approach to object creation for service type objects that other developers are familiar with, rather than higher order functions or function constructors. Although my method is kind of bespoke anyway so I could go either way. Another advantage of your approach is composing finer grained functions or objects with methods into more expansive services becomes delightfully easy.
>[1]: https://news.ycombinator.com/item?id=31547975 - I'd love to hear opinions on that.
I've tried to use TypeScriot DI containers... Oh I've tried.. But eventually they all just feel gross.
These days I'm perfectly happy having a bootstrap / createServices method for the application, or with multiple entry points each requiring a subset of services with different configurations, different create<command>Services functions. Works well for CLI apps. Downside is when there are too many entry points with different depenencies, like an HTTP API, you don't want to create a bootstrap method for each entrypoint. In this case I create all services once on bootup. I pass the request context as method argument. Don't have a perfect way yet of doing request-level services like GraphQL caching. Currently I lazy load request level services on request context.
comment 4y ago · link · parent
An ISaveable interface would need to be generic but "save" functions might take different numbers of arguments, and of different types.
I've found the advantage of interfaces to be dependency injection, where i can inject a different implementation of an interface without breakijg anything (eg save to s3, to google cloud storage, to filesystem, to memory), or a test version of the function/class.
Abstractions like ISaveable on the service interface just make the code more fragile in my experience in an attempt to save some extra but simple lines of code. Granted it may make sense on active record model classes though.
comment 4y ago · link · parent
interface IHasSaveProject {
saveProject(...): ...
}class HasSaveProject implements IHasSaveProject {
saveProject(...): {...}
}class Controller {
constructor(private readonly IHasSaveProject) {}
post(...) {
this
.hasSaveProject
.saveProject(...)
}
}And basically have a different class for every function
In cases where it really makes sense to have multiple methods on a single class, I do this
interface IProjectService extends IProjectService.IHasGetProject ,IProjectService.IHasGetProject {}
namespace IProjectService {
export interface IHasGetProject {
getProject(...): ...
}
export interface IHasSaveProject {
saveProject(...): ...
}
}class ProjectService implements IProjectService {
getProject(...): {...}
saveProject(...): {...}
}class Controller {
constructor(private readonly projectService: IProjectService) {}
// or
// constructor(private readonly projectService:
// IProjectService.IHasGetProject
// & IProjectService.IHasaveProject) {}
// or
// constructor(
// private readonly hasSaveProject: IProjectSercice.IHasSaveProject
// private readonly hasGetProject: IProjectSercice.IHasGetProject
// ) {}
...
}Seems to be working well for me. Lots of flexibility. Not sure how others like it though.
Please forgive my formatting