cofacts / rumors-site

Rumors list / creation UI, with server-side rendering
https://cofacts.tw
MIT License
83 stars 49 forks source link

Fix UI when adding categories to articles #575

Closed jiru closed 4 months ago

jiru commented 4 months ago

Closes #481.

The reason the UI was not refreshed was a regression introduced by cf550a0ca17a8b6b44f7839454b1758704e701c0. 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

coveralls commented 4 months ago

Coverage Status

coverage: 71.353%. remained the same when pulling 478d1578912bc3e2bec3baaa4e2915e992ca72e9 on jiru:fix_add_categories into 91dcbfb8de06d05f79047099f3d50d753932705c on cofacts:master.