themetalfleece / neogma

Object-Graph-Mapping neo4j framework, Fully-typed with TypeScript, for easy and flexible node and relationship operations
https://themetalfleece.github.io/neogma/
MIT License
117 stars 12 forks source link

Where parameters do not have relationship typings #65

Open Ansis100 opened 1 year ago

Ansis100 commented 1 year ago

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.

themetalfleece commented 1 year ago

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>