Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 3.10.0 #6662

Merged
merged 4 commits into from Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,7 +10,12 @@ The version headers in this history reflect the versions of Apollo Server itself

## vNEXT

- _Nothing yet! Stay tuned._

## v3.10.0

- Add `document`, `variables`, `headers` as an option in the `ApolloServerPluginLandingPageLocalDefault` plugins. The embedded version of Apollo Sandbox can now use these options as an initial state. [PR #6628](https://github.com/apollographql/apollo-server/pull/6628)
- Add `generateCacheKey` to `ApolloServerPluginResponseCache` to allow for custom cache keys. [PR #6655](https://github.com/apollographql/apollo-server/pull/6655)

## v3.9.0

Expand Down
1 change: 1 addition & 0 deletions docs/source/performance/caching.md
Expand Up @@ -472,3 +472,4 @@ In addition to [the `sessionId` function](#identifying-users-for-private-respons
| `extraCacheKeyData` | This function's return value (any JSON-stringifiable object) is added to the key for the cached response. For example, if your API includes translatable text, this function can return a string derived from `requestContext.request.http.headers.get('Accept-Language')`. |
| `shouldReadFromCache` | If this function returns `false`, Apollo Server _skips_ the cache for the incoming operation, even if a valid response is available. |
| `shouldWriteToCache` | If this function returns `false`, Apollo Server doesn't cache its response for the incoming operation, even if the response's `maxAge` is greater than `0`. |
| `generateCacheKey` | Customize generation of the cache key. By default, this is the SHA256 hash of the JSON encoding of an object containing relevant data. |
2 changes: 1 addition & 1 deletion packages/apollo-reporting-protobuf/package.json
@@ -1,6 +1,6 @@
{
"name": "apollo-reporting-protobuf",
"version": "3.3.1",
"version": "3.3.2",
"description": "Protobuf format for Apollo usage reporting",
"main": "generated/index.js",
"types": "generated/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-azure-functions/package.json
@@ -1,6 +1,6 @@
{
"name": "apollo-server-azure-functions",
"version": "3.9.0",
"version": "3.10.0",
"description": "Production-ready Node.js GraphQL server for Azure Functions",
"keywords": [
"GraphQL",
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-cloud-functions/package.json
@@ -1,6 +1,6 @@
{
"name": "apollo-server-cloud-functions",
"version": "3.9.0",
"version": "3.10.0",
"description": "Production-ready Node.js GraphQL server for Google Cloud Functions",
"keywords": [
"GraphQL",
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-cloudflare/package.json
@@ -1,6 +1,6 @@
{
"name": "apollo-server-cloudflare",
"version": "3.9.0",
"version": "3.10.0",
"description": "Production-ready Node.js GraphQL server for Cloudflare workers",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-core/package.json
@@ -1,6 +1,6 @@
{
"name": "apollo-server-core",
"version": "3.9.0",
"version": "3.10.0",
"description": "Core engine for Apollo GraphQL server",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-express/package.json
@@ -1,6 +1,6 @@
{
"name": "apollo-server-express",
"version": "3.9.0",
"version": "3.10.0",
"description": "Production-ready Node.js GraphQL server for Express",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-fastify/package.json
@@ -1,6 +1,6 @@
{
"name": "apollo-server-fastify",
"version": "3.9.0",
"version": "3.10.0",
"description": "Production-ready Node.js GraphQL server for Fastify",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-hapi/package.json
@@ -1,6 +1,6 @@
{
"name": "apollo-server-hapi",
"version": "3.9.0",
"version": "3.10.0",
"description": "Production-ready Node.js GraphQL server for Hapi",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-integration-testsuite/package.json
@@ -1,7 +1,7 @@
{
"name": "apollo-server-integration-testsuite",
"private": true,
"version": "3.9.0",
"version": "3.10.0",
"description": "Apollo Server Integrations testsuite",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-koa/package.json
@@ -1,6 +1,6 @@
{
"name": "apollo-server-koa",
"version": "3.9.0",
"version": "3.10.0",
"description": "Production-ready Node.js GraphQL server for Koa",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-lambda/package.json
@@ -1,6 +1,6 @@
{
"name": "apollo-server-lambda",
"version": "3.9.0",
"version": "3.10.0",
"description": "Production-ready Node.js GraphQL server for AWS Lambda",
"keywords": [
"GraphQL",
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-micro/package.json
@@ -1,6 +1,6 @@
{
"name": "apollo-server-micro",
"version": "3.9.0",
"version": "3.10.0",
"description": "Production-ready Node.js GraphQL server for Micro",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-plugin-base/package.json
@@ -1,6 +1,6 @@
{
"name": "apollo-server-plugin-base",
"version": "3.6.1",
"version": "3.6.2",
"description": "Apollo Server plugin base classes",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-plugin-response-cache/package.json
@@ -1,6 +1,6 @@
{
"name": "apollo-server-plugin-response-cache",
"version": "3.6.1",
"version": "3.7.0",
"description": "Apollo Server full query response cache",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
Expand Up @@ -86,6 +86,19 @@ interface Options<TContext = Record<string, any>> {
shouldWriteToCache?(
requestContext: GraphQLRequestContext<TContext>,
): ValueOrPromise<boolean>;

// This hook allows one to replace the function that is used to create a cache
// key. By default, it is the SHA-256 (from the Node `crypto` package) of the result of
// calling `JSON.stringify(keyData)`. You can override this to customize the serialization
// or the hash, or to make other changes like adding a prefix to keys to allow for
// app-specific prefix-based cache invalidation. You may assume that `keyData` is an object
// and that all relevant data will be found by the kind of iteration performed by
// `JSON.stringify`, but you should not assume anything about the particular fields on
// `keyData`.
generateCacheKey?(
requestContext: GraphQLRequestContext<Record<string, any>>,
keyData: unknown,
): string;
}

enum SessionMode {
Expand All @@ -98,18 +111,28 @@ function sha(s: string) {
return createHash('sha256').update(s).digest('hex');
}

interface BaseCacheKey {
interface BaseCacheKeyData {
source: string;
operationName: string | null;
variables: { [name: string]: any };
extra: any;
}

interface ContextualCacheKey {
interface ContextualCacheKeyData {
sessionMode: SessionMode;
sessionId?: string | null;
}

// We split the CacheKey type into two pieces just for convenience in the code
// below. Note that we don't actually export this type publicly (the
// generateCacheKey hook gets an `unknown` argument).
type CacheKeyData = BaseCacheKeyData & ContextualCacheKeyData;

type GenerateCacheKeyFunction = (
requestContext: GraphQLRequestContext<Record<string, any>>,
keyData: CacheKeyData,
) => string;

interface CacheValue {
// Note: we only store data responses in the cache, not errors.
//
Expand All @@ -126,12 +149,6 @@ interface CacheValue {
cacheTime: number; // epoch millis, used to calculate Age header
}

type CacheKey = BaseCacheKey & ContextualCacheKey;

function cacheKeyString(key: CacheKey) {
return sha(JSON.stringify(key));
}

function isGraphQLQuery(requestContext: GraphQLRequestContext<any>) {
return requestContext.operation?.operation === 'query';
}
Expand All @@ -148,8 +165,11 @@ export default function plugin(
'fqc:',
);

const generateCacheKey: GenerateCacheKeyFunction =
options.generateCacheKey ?? ((_, key) => sha(JSON.stringify(key)));

let sessionId: string | null = null;
let baseCacheKey: BaseCacheKey | null = null;
let baseCacheKey: BaseCacheKeyData | null = null;
let age: number | null = null;

return {
Expand All @@ -163,12 +183,15 @@ export default function plugin(
}

async function cacheGet(
contextualCacheKeyFields: ContextualCacheKey,
contextualCacheKeyFields: ContextualCacheKeyData,
): Promise<GraphQLResponse | null> {
const key = cacheKeyString({
const cacheKeyData = {
...baseCacheKey!,
...contextualCacheKeyFields,
});
};

const key = generateCacheKey(requestContext, cacheKeyData);

const serializedValue = await cache.get(key);
if (serializedValue === undefined) {
return null;
Expand Down Expand Up @@ -276,12 +299,15 @@ export default function plugin(
}

const cacheSetInBackground = (
contextualCacheKeyFields: ContextualCacheKey,
contextualCacheKeyFields: ContextualCacheKeyData,
): void => {
const key = cacheKeyString({
const cacheKeyData = {
...baseCacheKey!,
...contextualCacheKeyFields,
});
};

const key = generateCacheKey(requestContext, cacheKeyData);

const value: CacheValue = {
data,
cachePolicy: policyIfCacheable,
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-types/package.json
@@ -1,6 +1,6 @@
{
"name": "apollo-server-types",
"version": "3.6.1",
"version": "3.6.2",
"description": "Apollo Server shared types",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server/package.json
@@ -1,6 +1,6 @@
{
"name": "apollo-server",
"version": "3.9.0",
"version": "3.10.0",
"description": "Production ready GraphQL Server",
"author": "Apollo <packages@apollographql.com>",
"main": "dist/index.js",
Expand Down