Stronger typing in NaturalAbstractModelService
PowerKiKi opened this issue · comments
Adrien Crivelli commented
NaturalAbstractModelService.mapCreation()
and other map*
are loosely typed with unknown
because the whole class is not aware of the entire graphql query. Instead it is only aware of a sub-part of the graphql query.
A potential solution is to refactor so that TCreate
does not mean:
{
id: 123,
name: "foo"
}
but instead the whole query:
{
createUser: {
id: 123,
name: "foo"
}
}
And the the original TCreate
meaning should be reproducible with something like https://stackoverflow.com/a/73278870/37706. This might also help to type keys (the "createUser"
): https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html#capitalizestringtype
So final usage would be:
- class UserService extends NaturalAbstractModelService<User['user'], UserVariables, Users['users'], UsersVariables, CreateUser['createUser'], CreateUserVariables, UpdateUser['updateUser'], UpdateUserVariables, any, any>
+ class UserService extends NaturalAbstractModelService<User, UserVariables, Users, UsersVariables, CreateUser, CreateUserVariables, UpdateUser, UpdateUserVariables, any, any>