Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stronger typing in NaturalAbstractModelService #229

Open
PowerKiKi opened this issue Jan 30, 2023 · 0 comments
Open

Stronger typing in NaturalAbstractModelService #229

PowerKiKi opened this issue Jan 30, 2023 · 0 comments
Labels
BREAKING CHANGE enhancement New feature or request

Comments

@PowerKiKi
Copy link
Member

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>
@PowerKiKi PowerKiKi added the enhancement New feature or request label Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING CHANGE enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant