-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
✅ Deploy Preview for dailp canceled.
|
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
fragment CommentFields on Comment { | ||
id | ||
postedAt { | ||
timestamp | ||
date { | ||
year | ||
month | ||
day | ||
formattedDate | ||
} | ||
} | ||
postedBy { | ||
id | ||
displayName | ||
} | ||
textContent | ||
commentType | ||
} |
There was a problem hiding this comment.
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.
comments { | ||
id | ||
postedAt { | ||
timestamp | ||
date { | ||
year | ||
month | ||
day | ||
formattedDate | ||
} | ||
} | ||
postedBy { | ||
id | ||
displayName | ||
} | ||
textContent | ||
commentType | ||
...CommentFields | ||
} |
There was a problem hiding this comment.
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
... on AnnotatedForm { | ||
__typename | ||
id | ||
comments { | ||
...CommentFields | ||
} | ||
} | ||
... on DocumentParagraph { | ||
__typename | ||
id | ||
comments { | ||
...CommentFields | ||
} |
There was a problem hiding this comment.
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.
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!