Skip to content

Commit

Permalink
Fix UI when adding categories to articles
Browse files Browse the repository at this point in the history
Closes #481.

The reason the UI was not refreshed was a regression introduced by cf550a0.
Adding the argument "(statuses: $articleCategoryStatuses)" changes the key used by InMemoryCache
from "articleCategories" to "articleCategories({"statuses":["NORMAL"]})".
This results in cache.readFragment() (called in components/ArticleCategories/CategoryOption.js throwing this error:
```
Invariant Violation: Can't find field articleCategories on object {
  "id": ...,
  "text": ...
  ...
  "articleCategories({\"statuses\":[\"NORMAL\"]})": [
    {
      "type": "id",
      "generated": false,
      "id": "ArticleCategory:...__...",
      "typename": "ArticleCategory"
    }
  ],
  "stats": [
    ...
  ],
  "user": {
    ...
  }
}
```

This commits solves this issue by forcing the key to be "articleCategories".

The technique of using an @connection directive is documented here:
https://www.apollographql.com/docs/react/data/directives/#connection
  • Loading branch information
jiru committed Jul 23, 2024
1 parent 91dcbfb commit adb920f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pages/article/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const LOAD_ARTICLE = gql`
cooccurrences {
...CooccurrenceSectionData
}
articleCategories(statuses: $articleCategoryStatuses) {
articleCategories(statuses: $articleCategoryStatuses) @connection(key: "articleCategories") {

Check failure on line 176 in pages/article/[id].js

View workflow job for this annotation

GitHub Actions / install-and-test

Insert `⏎·······`
...ArticleCategoryData
...AddCategoryDialogData
}
Expand Down Expand Up @@ -221,7 +221,7 @@ const LOAD_ARTICLE_FOR_USER = gql`
articleReplies(statuses: $articleReplyStatuses) {
...ArticleReplyForUser
}
articleCategories(statuses: $articleCategoryStatuses) {
articleCategories(statuses: $articleCategoryStatuses) @connection(key: "articleCategories") {

Check failure on line 224 in pages/article/[id].js

View workflow job for this annotation

GitHub Actions / install-and-test

Insert `⏎·······`
...ArticleCategoryDataForUser
...AddCategoryDialogData
}
Expand Down

0 comments on commit adb920f

Please sign in to comment.