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
4 changes: 3 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@
"fast-deep-equal": "^3.1.3",
"fs-extra": "^11.0.0",
"graphql": "^16.8.1",
"graphql-depth-limit": "^1.1.0",
"graphql-upload": "^15.0.2",
"image-size": "^2.0.0",
"intersection-observer": "^0.12.0",
Expand All @@ -299,7 +300,8 @@
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"@types/resolve": "^1.20.2",
"@types/uuid": "^11.0.0"
"@types/uuid": "^11.0.0",
"@types/graphql-depth-limit": "^1.1.6"
},
"preconstruct": {
"entrypoints": [
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/lib/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { GraphQLError, type GraphQLFormattedError } from 'graphql'
import { type ApolloServerOptions, ApolloServer } from '@apollo/server'
import { ApolloServerPluginLandingPageDisabled } from '@apollo/server/plugin/disabled'
import { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default'

import depthLimit from 'graphql-depth-limit'
// @ts-expect-error
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.js'
import type { KeystoneContext, KeystoneConfig } from '../types'
Expand Down Expand Up @@ -74,6 +76,10 @@ export async function createExpressServer(
...apolloConfig,
formatError: formatError(config.graphql),
schema: context.graphql.schema,
validationRules: [
depthLimit(config.graphql.maxDepth ?? 20),
...(apolloConfig?.validationRules ?? []),
],
plugins:
config.graphql.playground === 'apollo'
? apolloConfig?.plugins
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/types/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,16 @@ export type KeystoneConfigPre<TypeInfo extends BaseKeystoneTypeInfo = BaseKeysto
* @default 'schema.graphql'
*/
extendGraphqlSchema?: (schema: GraphQLSchema) => GraphQLSchema

/**
* The maximum depth allowed for queries.
* @default 20
*/
maxDepth?: number
}

lists: Record<string, ListConfig<any>>

server?: {
/** Configuration options for the cors middleware. Set to `true` to use Keystone's defaults */
cors?: boolean | CorsOptions
Expand Down