Skip to content

Commit

Permalink
fix: ensure GQL schema cache key also includes current tenant ID and …
Browse files Browse the repository at this point in the history
…locale code
  • Loading branch information
adrians5j committed Aug 14, 2023
1 parent fcd845e commit 2b34707
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/handler-graphql/src/createGraphQLHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,22 @@ const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year

const createCacheKey = (context: Context) => {
const plugins = getSchemaPlugins(context);
// TODO: in the near future, we have to assign a fixed name to every GraphQLSchema plugin,
// to be able to create a reliable cache key.
return plugins.length.toString();
// TODO: in the near future, we have to assign a fixed name to every
// TODO: GraphQLSchema plugin, to be able to create a reliable cache key.

// @ts-ignore TODO: `getCurrentTenant` should be injected as a parameter.
// @ts-ignore TODO: We should not be accessing `context` like this here.
const { getCurrentTenant } = context.tenancy;

// @ts-ignore TODO: `getContentLocale` should be injected as a parameter.
// @ts-ignore TODO: We should not be accessing `context` like this here.
const { getContentLocale } = context.i18n;

return [
`tenant:${getCurrentTenant().id}`,
`locale:${getContentLocale().code}`,
plugins.length.toString()
].join("#");
};

const createRequestBody = (body: unknown): GraphQLRequestBody | GraphQLRequestBody[] => {
Expand Down

0 comments on commit 2b34707

Please sign in to comment.