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

Format queries/mutations for comments to work with GraphCache #382

Merged
merged 3 commits into from
Dec 29, 2023

Conversation

CharlieMcVicker
Copy link
Collaborator

Jira: Comments only sometimes work

Currently, comments are posted successfully, but the UX doesn't update automatically. By changing what we fetch in the queries (there is no change to the typescript here) we will get the caching behavior we want. That is, when you post a comment, the word/paragraph comments query will be updated.

This PR should be a great example of making something work with GraphCache!

Copy link

netlify bot commented Dec 29, 2023

Deploy Preview for dailp canceled.

Name Link
🔨 Latest commit 23bcc02
🔍 Latest deploy log https://app.netlify.com/sites/dailp/deploys/658f4e438d692d000816dccf

Copy link
Collaborator Author

@CharlieMcVicker CharlieMcVicker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tour of changes

query WordComments($wordId: UUID!) {
wordById(id: $wordId) {
id
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We always need to fetch IDs if we want this to work

Comment on lines +430 to +447
fragment CommentFields on Comment {
id
postedAt {
timestamp
date {
year
month
day
formattedDate
}
}
postedBy {
id
displayName
}
textContent
commentType
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These common fields used by two queries and the post mutation are now in a fragment.

Comment on lines 452 to 454
comments {
id
postedAt {
timestamp
date {
year
month
day
formattedDate
}
}
postedBy {
id
displayName
}
textContent
commentType
...CommentFields
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fragment replaces these fields here

Comment on lines 594 to +606
... on AnnotatedForm {
__typename
id
comments {
...CommentFields
}
}
... on DocumentParagraph {
__typename
id
comments {
...CommentFields
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We fetch the comments and the fields we need when we post, so we have an up-to-date version on the frontend as soon as the mutation finishes.

@GracefulLemming GracefulLemming merged commit d0a8a48 into main Dec 29, 2023
4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants