-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3820 from thematters/feat/me-drafts-cache
feat(draft): revise local cache updating on /me/drafts
- Loading branch information
Showing
8 changed files
with
115 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { DataProxy } from 'apollo-cache' | ||
|
||
import { MeDraftFeedQuery } from '~/gql/graphql' | ||
|
||
export const updateUserDrafts = ({ | ||
cache, | ||
targetId, | ||
type, | ||
}: { | ||
cache: DataProxy | ||
targetId?: string | ||
type: 'remove' | 'add' | ||
}) => { | ||
// FIXME: circular dependencies | ||
const { ME_DRAFTS_FEED } = require('~/views/Me/Drafts/gql') | ||
|
||
let draftsData: MeDraftFeedQuery | null = null | ||
try { | ||
draftsData = cache.readQuery<MeDraftFeedQuery>({ query: ME_DRAFTS_FEED }) | ||
} catch (e) { | ||
// | ||
} | ||
|
||
let draftEdges = draftsData?.viewer?.drafts.edges || [] | ||
|
||
switch (type) { | ||
case 'remove': | ||
draftEdges = draftEdges.filter((edge) => edge.node.id !== targetId) | ||
break | ||
} | ||
|
||
if (draftsData) { | ||
cache.writeQuery({ | ||
query: ME_DRAFTS_FEED, | ||
data: { | ||
...draftsData, | ||
viewer: { | ||
...draftsData?.viewer, | ||
drafts: { | ||
...draftsData?.viewer?.drafts, | ||
edges: draftEdges, | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import gql from 'graphql-tag' | ||
|
||
import { DraftDigest } from '~/components/DraftDigest' | ||
|
||
export const ME_DRAFTS_FEED = gql` | ||
query MeDraftFeed($after: String) { | ||
viewer { | ||
id | ||
drafts(input: { first: 20, after: $after }) | ||
@connection(key: "viewerDrafts") { | ||
pageInfo { | ||
startCursor | ||
endCursor | ||
hasNextPage | ||
} | ||
edges { | ||
cursor | ||
node { | ||
...DraftDigestFeedDraft | ||
} | ||
} | ||
} | ||
} | ||
} | ||
${DraftDigest.Feed.fragments.draft} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6d9bdde
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.
Successfully deployed to the following URLs:
matters-web – ./
matters-web-matters.vercel.app
matters-web-git-develop-matters.vercel.app
matters-web.vercel.app
web-dev.matters.town