Skip to content

Commit 9a59562

Browse files
rjgtavRicardo TavaresDanRibbens
authored
perf(graphql): use depth 0 in auth/apiKey for graphQL requests (#13895)
### What? Sets depth to 0 when finding the corresponding user in auth/apiKey. This matches the current behavior of auth/jwt ### Why? Optimizes the authentication step by making just one database query instead of two, when using sessions. Particularly impactful when there's latency between Payload and the database ### How? By leveraging the already existing isGraphQL flag of the AuthStrategyFunction Co-authored-by: Ricardo Tavares <rtavares@cloudflare.com> Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
1 parent 1d1240f commit 9a59562

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • packages/payload/src/auth/strategies

packages/payload/src/auth/strategies/apiKey.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { AuthStrategyFunction } from '../index.js'
77

88
export const APIKeyAuthentication =
99
(collectionConfig: SanitizedCollectionConfig): AuthStrategyFunction =>
10-
async ({ headers, payload }) => {
10+
async ({ headers, isGraphQL = false, payload }) => {
1111
const authHeader = headers.get('Authorization')
1212

1313
if (authHeader?.startsWith(`${collectionConfig.slug} API-Key `)) {
@@ -53,7 +53,7 @@ export const APIKeyAuthentication =
5353

5454
const userQuery = await payload.find({
5555
collection: collectionConfig.slug,
56-
depth: collectionConfig.auth.depth,
56+
depth: isGraphQL ? 0 : collectionConfig.auth.depth,
5757
limit: 1,
5858
overrideAccess: true,
5959
pagination: false,

0 commit comments

Comments
 (0)