Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3866a8a

Browse files
committed
Add private scoping to currentUser and a private cache for its storage.
While a `User` is used in many different aspects of the app (e.g. the user who posted a `Comment`, the owner of a `Repository`), the `currentUser` is intended to be the `User` who is currently authorized to the app and should not be cached by Engine. This app is already aware of how to quantify the difference between sessions by its `sessionAuth.header` configuration in `engineConfig` (api/server.js). By adding a `@cacheControl(scope: PRIVATE)` decorator on the `currentUser` field, we instruct Engine caching that this field is subject to this isolation. While the private data will still be cached, the contents of the cached resource are only available to a user from the same session (based on the `Authorization` header). There are further authorization configuration options, and those can be seen at: https://www.apollographql.com/docs/engine/caching.html#public-vs-private.
1 parent 797abc8 commit 3866a8a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

api/schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type Query {
4040
): Entry
4141
4242
# Return the currently logged in user, or null if nobody is logged in
43-
currentUser: User
43+
currentUser: User @cacheControl(scope: PRIVATE)
4444
}
4545
4646
# The type of vote to record, when submitting a vote

api/server.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ export function run({ ENGINE_API_KEY, PORT: portFromEnv = 3010 } = {}) {
4444
apiKey: ENGINE_API_KEY,
4545
stores: [
4646
{
47-
name: 'embeddedCache',
47+
name: 'publicResponseCache',
48+
inMemory: {
49+
cacheSize: 10485760,
50+
},
51+
},
52+
{
53+
name: 'privateResponseCache',
4854
inMemory: {
4955
cacheSize: 10485760,
5056
},
@@ -60,12 +66,12 @@ export function run({ ENGINE_API_KEY, PORT: portFromEnv = 3010 } = {}) {
6066
store: 'pq',
6167
},
6268
sessionAuth: {
63-
store: 'embeddedCache',
69+
store: 'privateResponseCache',
6470
header: 'Authorization',
6571
},
6672
queryCache: {
67-
publicFullQueryStore: 'embeddedCache',
68-
privateFullQueryStore: 'embeddedCache',
73+
publicFullQueryStore: 'publicResponseCache',
74+
privateFullQueryStore: 'privateResponseCache',
6975
},
7076
reporting: {
7177
debugReports: true,

0 commit comments

Comments
 (0)