Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf57b367

Browse files
committed
apollo decorator with local cache
1 parent0c9b0b9 commitf57b367

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

‎web-app/src/services/apollo/index.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,47 @@
1-
importApolloClientfrom'apollo-boost'
1+
importApolloClient,{InMemoryCache}from'apollo-boost'
22

33
constclient=newApolloClient({
44
uri:process.env.REACT_APP_GQL_URI,
5+
headers:{
6+
Authorization:process.env.GQL_AUTH_TOKEN,
7+
},
8+
cache:newInMemoryCache(),
9+
resolvers:{
10+
Mutation:{
11+
setStatus:(_root,variables,{ cache, getCacheKey})=>{
12+
// TODO: optimize status setting to act on diffs
13+
14+
// set local cache
15+
functionset(typename:string,id:string,status:'ACTIVE'|'COMPLETE'){
16+
constwriteId=getCacheKey({__typename:typename, id})
17+
constdata={ status}
18+
cache.writeData({id:writeId, data})
19+
}
20+
21+
const{ progress, position}=variables
22+
23+
// set level progress & active
24+
for(constlevelIdofObject.keys(progress.levels)){
25+
set('Level',levelId,'COMPLETE')
26+
}
27+
set('Level',position.levelId,'ACTIVE')
28+
29+
// set stage progress & active
30+
for(conststageIdofObject.keys(progress.stages)){
31+
set('Stage',stageId,'COMPLETE')
32+
}
33+
set('Stage',position.stageId,'ACTIVE')
34+
35+
// set step progress & active
36+
for(conststepIdofObject.keys(progress.steps)){
37+
set('Step',stepId,'COMPLETE')
38+
}
39+
set('Step',position.stepId,'ACTIVE')
40+
41+
returnnull
42+
},
43+
},
44+
},
545
})
646

747
exportdefaultclient

‎web-app/stories/utils/ApolloDecorator.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
importReact,{Fragment}from'react'
2-
importApolloClientfrom'apollo-boost'
2+
importclientfrom'../../src/services/apollo'
33
import{ApolloProvider}from'@apollo/react-hooks'
44

5-
constgraphqlClient=newApolloClient({
6-
uri:'http://localhost:4000/graphql',
7-
headers:{
8-
Authorization:process.env.GQL_AUTH_TOKEN,
9-
},
10-
})
11-
125
functionStorybookProvider({ children}){
136
return(
14-
<ApolloProviderclient={graphqlClient}>
7+
<ApolloProviderclient={client}>
158
<Fragment>{children}</Fragment>
169
</ApolloProvider>
1710
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp