neogma icon indicating copy to clipboard operation
neogma copied to clipboard

Where parameters do not have relationship typings

Open Ansis100 opened this issue 1 year ago • 1 comments

https://github.com/themetalfleece/neogma/blob/da28eccb3221476d5d7693be65f84297d8ea0532/src/Queries/Where/Where.ts#L109-L116

The key of WhereParamsI is a string type. This can cause errors that are difficult to debug. For example:

user.findRelationships({
  alias: 'Group',
  where: { target: { grpName: 'Administrators' } },
});

If the model of user groups has a property called groupName then this will fail only at runtime when findRelationships returns zero results.

It would be better if the key of WhereParamsI were typed to be the keys of the related node properties.

Ansis100 avatar Jun 08 '23 12:06 Ansis100

That's true, but it's a bit difficult to type properly for nested relationships with where. I'll have a fresh look though. Until then, you can use the satisfies keyword to add some inline type safety, like:

where: {
  name: 'Jason'
} satisfies Partial<UserProperties>

themetalfleece avatar Jun 08 '23 19:06 themetalfleece