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

Add cache: "bounded" and persistedQueries: false to default Apollo Server config #7888

Merged
merged 2 commits into from
Sep 6, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/many-bulldogs-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': major
---

Changes default Apollo Server configuration to use `cache: "bounded"` and `persistedQueries: false`
5 changes: 4 additions & 1 deletion packages/core/src/lib/server/createApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ApolloServer as ApolloServerExpress } from 'apollo-server-express';
import {
ApolloServerPluginLandingPageDisabled,
ApolloServerPluginLandingPageGraphQLPlayground,
Config,
} from 'apollo-server-core';
import type { CreateContext, GraphQLConfig, SessionStrategy } from '../../types';
import { createSessionContext } from '../../session';
Expand Down Expand Up @@ -63,13 +64,15 @@ const _createApolloServerConfig = ({
}: {
graphQLSchema: GraphQLSchema;
graphqlConfig?: GraphQLConfig;
}) => {
}): Config => {
const apolloConfig = graphqlConfig?.apolloConfig;
const playgroundOption = graphqlConfig?.playground ?? process.env.NODE_ENV !== 'production';

return {
schema: graphQLSchema,
debug: graphqlConfig?.debug, // If undefined, use Apollo default of NODE_ENV !== 'production'
cache: 'bounded',
persistedQueries: false,
...apolloConfig,
plugins:
playgroundOption === 'apollo'
Expand Down
7 changes: 2 additions & 5 deletions tests/api-tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ let prevConsoleWarn = console.warn;
console.warn = function (...args: unknown[]) {
if (
typeof args[0] === 'string' &&
(args[0].endsWith(
args[0].endsWith(
// this is expected
'There are already 10 instances of Prisma Client actively running.'
) ||
// we should really enforce a safe default for this though
args[0] ===
'Persisted queries are enabled and are using an unbounded cache. Your server is vulnerable to denial of service attacks via memory exhaustion. Set `cache: "bounded"` or `persistedQueries: false` in your ApolloServer constructor, or see https://go.apollo.dev/s/cache-backends for other alternatives.')
)
) {
return;
}
Expand Down