File tree 2 files changed +21
-6
lines changed
2 files changed +21
-6
lines changed Original file line number Diff line number Diff line change 5
5
>
6
6
<ApolloSubscribeToMore
7
7
:document =" require('../graphql/suggestionAdded.gql')"
8
- :updateQuery =" (previousResult, { subscriptionData }) => ({
9
- suggestions: [
10
- ...previousResult.suggestions,
11
- subscriptionData.data.suggestionAdded
12
- ]
13
- })"
8
+ :updateQuery =" (previousResult, { subscriptionData }) => {
9
+ const newSuggestion = subscriptionData.data.suggestionAdded
10
+ if (previousResult.suggestions.find(s => s.id === newSuggestion.id)) {
11
+ return previousResult
12
+ }
13
+ return {
14
+ suggestions: [
15
+ ...previousResult.suggestions,
16
+ newSuggestion
17
+ ]
18
+ }
19
+ }"
14
20
/>
15
21
16
22
<ApolloSubscribeToMore
Original file line number Diff line number Diff line change 1
1
// Subs
2
2
const channels = require ( '../channels' )
3
+ // Connectors
4
+ const { log } = require ( '../utils/logger' )
3
5
4
6
const suggestions = [ ]
5
7
@@ -25,18 +27,23 @@ function add (suggestion, context) {
25
27
suggestionAdded : suggestion
26
28
} )
27
29
30
+ log ( 'Suggestion added' , suggestion . id )
31
+
28
32
return suggestion
29
33
}
30
34
31
35
function remove ( id , context ) {
32
36
const suggestion = findOne ( id )
37
+ if ( ! suggestion ) return
33
38
const index = suggestions . indexOf ( suggestion )
34
39
suggestions . splice ( index , 1 )
35
40
36
41
context . pubsub . publish ( channels . SUGGESTION_REMOVED , {
37
42
suggestionRemoved : suggestion
38
43
} )
39
44
45
+ log ( 'Suggestion removed' , suggestion . id )
46
+
40
47
return suggestion
41
48
}
42
49
@@ -55,6 +62,8 @@ function update (data, context) {
55
62
suggestionUpdated : suggestion
56
63
} )
57
64
65
+ log ( 'Suggestion updated' , suggestion . id )
66
+
58
67
return suggestion
59
68
}
60
69
You can’t perform that action at this time.
0 commit comments