Skip to content

Stronger typing in NaturalAbstractModelService #229

Description

@PowerKiKi

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>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions