-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Description
Describe the bug
When trying to create hooks the CreateOrUpdateHookParams<G> type is frustrating to work with.
- It has an
entitiesproperty, but that property is not actually there at runtime, the correct one to be using isargs.items. args.itemsis of typePartial<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.params.contextis 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)
Metadata
Metadata
Assignees
Labels
No labels