Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion packages/mirrormedia/keystone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,27 @@ const graphqlConfig: GraphQLConfig = {
envVar.accessControlStrategy === 'gql' && envVar.cache.isEnabled
? {
plugins: [
responseCachePlugin(),
responseCachePlugin({
extraCacheKeyData: async (requestContext) => {
const scope = requestContext.request.http?.headers.get(
'x-access-token-scope'
)
const acl =
typeof scope === 'string'
? scope.match(/read:member-posts:([^\s]*)/i)?.[1]
: ''

/**
* 目前僅有文章有權限設定,因此,在 cache 時,需藉由 request 的權限設定,來產生對應的 cache key
*
* @see https://www.apollographql.com/docs/apollo-server/performance/caching#configuring-reads-and-writes
* @see https://github.com/mirror-media/weekly-api-server/blob/226f7a39179901d76e681417442b13ed27db502d/src/middlewares/auth.js#L137
*/
return {
'member-post-acl': acl,
}
},
}),
ApolloServerPluginCacheControl({
defaultMaxAge: envVar.cache.maxAge,
}),
Expand Down
3 changes: 0 additions & 3 deletions packages/mirrormedia/lists/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,6 @@ const listConfigurations = list({
defaultFieldMode: itemViewFunction,
},
},
graphql: {
cacheHint: { maxAge: 0, scope: 'PRIVATE' },
},
access: {
operation: {
query: allowRoles(admin, moderator, editor),
Expand Down