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

CreateOrUpdateHookParams typing needs improvement #1447

Open
thekevinbrown opened this issue Dec 11, 2024 · 0 comments
Open

CreateOrUpdateHookParams typing needs improvement #1447

thekevinbrown opened this issue Dec 11, 2024 · 0 comments

Comments

@thekevinbrown
Copy link
Member

Describe the bug
When trying to create hooks the CreateOrUpdateHookParams<G> type is frustrating to work with.

  1. It has an entities property, but that property is not actually there at runtime, the correct one to be using is args.items.
  2. args.items is of type Partial<G>[], which is...kind of correct, but nested entities are not typed correctly as GQL inputs, for example if this entity has a many to one relationship with another, and you want to set the foreign key, you'd do this: params.args.items?.forEach((entity) => entity.relationshipProperty = { id: '5' }, which is perfectly valid, but the types tell you that you need to fill out all properties on this entity, which is not true.
  3. params.context is not typed well at all, and it's difficult to pull values out of the user context to reference in your hook.

To Reproduce
Steps to reproduce the behaviour:

Build a hook that sets the current user as createdBy on every entity of that type which is created.

Expected behavior
Expected types to correctly define the shape of the context, or at least provide a generic param for it. Also expected types to be aware of foreign key reference assignments.

Actual behavior
What actually happened.

Point 2:

Type '{ id: string; }' is missing the following properties from type 'OtherEntity': [all required fields](2740);

Point 3:

Property 'user' does not exist on type 'object'.ts(2339)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant