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

[Multi-links field] Updating a Links field displays an Error #5437

Closed
thaisguigon opened this issue May 16, 2024 · 2 comments · Fixed by #5473
Closed

[Multi-links field] Updating a Links field displays an Error #5437

thaisguigon opened this issue May 16, 2024 · 2 comments · Fixed by #5473
Assignees
Labels
type: bug Something isn't working

Comments

@thaisguigon
Copy link
Contributor

Bug Description

When a Links field is updated, an error is displayed:

Image

Expected behavior

The update is successful.

Technical inputs

Seems to be linked to Apollo cache. Upgrading @apollo/client to v3.10.4 prints a warning in the console instead of throwing an error:

Image

It might be because the Links field seems to somehow have a __typename property in Apollo's cache, so Apollo considers it as a record and tries to match the object's cache with an id, but the Links field value has no id so it can't find it.
=> Find where this __typename is added and see if removing it from the Links object in the cache fixes this.
Maybe in getRecordNodeFromRecord?

@thaisguigon thaisguigon added the type: bug Something isn't working label May 16, 2024
@thaisguigon thaisguigon self-assigned this May 16, 2024
Copy link

greptile-apps bot commented May 16, 2024

Disclaimer: This comment was automatically generated with AI. It can give some useful hints as to where to look for, but sometimes it can also give very inaccurate answers so takes this with a pinch of salt :).
Investigate the getRecordNodeFromRecord function in src/utils/recordUtils.js to see where __typename might be added to the Links field. Additionally, check the updateRecordFromCache function in src/cache/updateCache.js for handling of the __typename property. Removing or correctly managing the __typename property in these functions should resolve the issue.

References

@thaisguigon
Copy link
Contributor Author

Update: the __typename comes from the backend by composite field design.
Instead of removing the __typename, the solution was to add FieldMetadataType.Links to the field types that need a __typename in the cache in getRecordNodeFromRecord, so Apollo knows how to merge it with the existing data when updating the cache.

charlesBochet pushed a commit that referenced this issue May 22, 2024
Closes #5375

<img width="381" alt="image"
src="https://github.com/twentyhq/twenty/assets/3098428/d87773df-c685-466b-ae35-a8349f79df48">

_____

~~Note that I ugraded `@apollo/client` to v3.10.4 because current
version is causing an error when trying to write the Links field in the
cache in `updateRecordFromCache` (`TypeError: Cannot convert object to
primitive value`). After upgrade, the error is gone but console still
prints a warning (here the custom object name is `Listing` and the Links
field name is `website`):~~

<img width="964" alt="image"
src="https://github.com/twentyhq/twenty/assets/3098428/834b8909-e8dc-464a-8c5a-6b7e4c964a7f">

~~It might be because the Links field seems to somehow have a
`__typename` property in Apollo's cache, so Apollo considers it as a
record and tries to match the object's cache with an id, but the Links
field value has no id so it can't find it.
We might want to find where this `__typename` is added and remove it
from the Links object in the cache.~~

Edit: will fix this in another PR as upgrading `@apollo/client` +
`apollo-upload-client` seems to break types and/or tests. Related issue:
[#5437](#5437)
Weiko pushed a commit that referenced this issue May 31, 2024
Closes #5375

<img width="381" alt="image"
src="https://github.com/twentyhq/twenty/assets/3098428/d87773df-c685-466b-ae35-a8349f79df48">

_____

~~Note that I ugraded `@apollo/client` to v3.10.4 because current
version is causing an error when trying to write the Links field in the
cache in `updateRecordFromCache` (`TypeError: Cannot convert object to
primitive value`). After upgrade, the error is gone but console still
prints a warning (here the custom object name is `Listing` and the Links
field name is `website`):~~

<img width="964" alt="image"
src="https://github.com/twentyhq/twenty/assets/3098428/834b8909-e8dc-464a-8c5a-6b7e4c964a7f">

~~It might be because the Links field seems to somehow have a
`__typename` property in Apollo's cache, so Apollo considers it as a
record and tries to match the object's cache with an id, but the Links
field value has no id so it can't find it.
We might want to find where this `__typename` is added and remove it
from the Links object in the cache.~~

Edit: will fix this in another PR as upgrading `@apollo/client` +
`apollo-upload-client` seems to break types and/or tests. Related issue:
[#5437](#5437)

followup

followup

followup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

1 participant