@@ -7,40 +7,66 @@ import {
7
7
fetchExchange ,
8
8
dedupExchange ,
9
9
subscriptionExchange
10
- } from "urql" ; ;
10
+ } from "urql" ;
11
11
import { cacheExchange } from '@urql/exchange-graphcache' ;
12
12
// import { suspenseExchange } from '@urql/exchange-suspense';
13
13
import { BrowserRouter } from 'react-router-dom' ;
14
14
import "./styles/index.css" ;
15
15
import App from "./components/App" ;
16
- import { AUTH_TOKEN , LINKS_PER_PAGE } from './constants'
16
+ import { AUTH_TOKEN , LINKS_PER_PAGE } from './constants' ;
17
17
import { FEED_QUERY } from './components/LinkList' ;
18
18
import * as serviceWorker from "./serviceWorker" ;
19
+ // import { timeDifferenceForDate } from './utils';
19
20
20
21
const cache = cacheExchange ( {
21
22
keys : {
23
+ // TODO: evaluate if we're not indicating wrong things by
24
+ // warning on these.
22
25
Feed : data => data . id || data . _id || null ,
23
- Link : data => data . id || data . _id || null
26
+ Link : data => data . id || data . _id || null ,
24
27
} ,
28
+ // Optimistic is not possible due to the nature of the data-structure
29
+ // every vote needs to have an unique id for a unique userId...
30
+
31
+ // We could write a custom resolver to format the datetime of a post
32
+ // to indicate the text of x time ago.
33
+ // TODO: found inconsistency with resolvers
34
+ // Initial write does not respect the resolvers given for querying data.
35
+ // resolvers: {
36
+ // Link: {
37
+ // createdAt: (parent) => {
38
+ // console.log('in link resolver');
39
+ // return timeDifferenceForDate(parent.createdAt);
40
+ // }
41
+ // }
42
+ // },
43
+
44
+ // Mutations that need updates due to adding/removing/... to a list
45
+ // Will most likely come here. We can't make assumptions for adding to
46
+ // a list.
25
47
updates : {
26
48
Mutation : {
27
49
post : ( { post } , _ , cache ) => {
28
- const first = LINKS_PER_PAGE
29
- const skip = 0
30
- const orderBy = 'createdAt_DESC'
50
+ const first = LINKS_PER_PAGE ;
51
+ const skip = 0 ;
52
+ const orderBy = 'createdAt_DESC' ;
53
+ // TODO: update @urql /exchange-graphcache for this to work
31
54
cache . updateQuery ( FEED_QUERY , { first, skip, orderBy } , data => {
32
55
data . feed . links . unshift ( post ) ;
56
+ data . feed . count += 1 ;
33
57
return data ;
34
58
} ) ;
35
59
} ,
36
60
} ,
37
61
Subscription : {
38
62
newLink : ( { newLink } , _ , cache ) => {
39
- const first = LINKS_PER_PAGE
40
- const skip = 0
41
- const orderBy = 'createdAt_DESC'
63
+ const first = LINKS_PER_PAGE ;
64
+ const skip = 0 ;
65
+ const orderBy = 'createdAt_DESC' ;
66
+ // TODO: update @urql /exchange-graphcache for this to work
42
67
cache . updateQuery ( FEED_QUERY , { first, skip, orderBy } , data => {
43
68
data . feed . links . unshift ( newLink ) ;
69
+ data . feed . count += 1 ;
44
70
return data ;
45
71
} ) ;
46
72
}
0 commit comments