diff --git a/src/auth/graphql/resolvers/login.ts b/src/auth/graphql/resolvers/login.ts index b46e9e34cb..e5898452bf 100644 --- a/src/auth/graphql/resolvers/login.ts +++ b/src/auth/graphql/resolvers/login.ts @@ -11,6 +11,7 @@ function loginResolver(collection: Collection) { }, req: context.req, res: context.res, + depth: 0, }; const result = login(options); diff --git a/src/auth/graphql/resolvers/me.ts b/src/auth/graphql/resolvers/me.ts index 865e23dd26..d61292e4b9 100644 --- a/src/auth/graphql/resolvers/me.ts +++ b/src/auth/graphql/resolvers/me.ts @@ -6,6 +6,7 @@ function meResolver(collection: Collection): any { const options = { collection, req: context.req, + depth: 0, }; return me(options); } diff --git a/src/auth/graphql/resolvers/refresh.ts b/src/auth/graphql/resolvers/refresh.ts index 09c7d98cec..e9427626a2 100644 --- a/src/auth/graphql/resolvers/refresh.ts +++ b/src/auth/graphql/resolvers/refresh.ts @@ -18,6 +18,7 @@ function refreshResolver(collection: Collection) { token, req: context.req, res: context.res, + depth: 0, }; const result = await refresh(options); diff --git a/src/auth/graphql/resolvers/resetPassword.ts b/src/auth/graphql/resolvers/resetPassword.ts index 81a1b27bdd..5844992f6d 100644 --- a/src/auth/graphql/resolvers/resetPassword.ts +++ b/src/auth/graphql/resolvers/resetPassword.ts @@ -13,6 +13,7 @@ function resetPasswordResolver(collection: Collection) { req: context.req, res: context.res, api: 'GraphQL', + depth: 0, }; const result = await resetPassword(options); diff --git a/src/auth/operations/resetPassword.ts b/src/auth/operations/resetPassword.ts index 678e356257..c4e04830f8 100644 --- a/src/auth/operations/resetPassword.ts +++ b/src/auth/operations/resetPassword.ts @@ -23,6 +23,7 @@ export type Arguments = { req: PayloadRequest overrideAccess?: boolean res?: Response + depth?: number } async function resetPassword(args: Arguments): Promise { @@ -45,6 +46,7 @@ async function resetPassword(args: Arguments): Promise { }, overrideAccess, data, + depth, } = args; // ///////////////////////////////////// @@ -119,7 +121,7 @@ async function resetPassword(args: Arguments): Promise { args.res.cookie(`${config.cookiePrefix}-token`, token, cookieOptions); } - const fullUser = await payload.findByID({ collection: collectionConfig.slug, id: user.id, overrideAccess }); + const fullUser = await payload.findByID({ collection: collectionConfig.slug, id: user.id, overrideAccess, depth }); return { token, user: fullUser }; } diff --git a/src/fields/hooks/afterRead/index.ts b/src/fields/hooks/afterRead/index.ts index b9d097bb38..a31a1edec9 100644 --- a/src/fields/hooks/afterRead/index.ts +++ b/src/fields/hooks/afterRead/index.ts @@ -33,13 +33,8 @@ export async function afterRead(args: Args): Promise { const fieldPromises = []; const populationPromises = []; - let depth = 0; - - if (req.payloadAPI === 'REST' || req.payloadAPI === 'local') { - depth = (incomingDepth || incomingDepth === 0) ? parseInt(String(incomingDepth), 10) : req.payload.config.defaultDepth; - - if (depth > req.payload.config.maxDepth) depth = req.payload.config.maxDepth; - } + let depth = (incomingDepth || incomingDepth === 0) ? parseInt(String(incomingDepth), 10) : req.payload.config.defaultDepth; + if (depth > req.payload.config.maxDepth) depth = req.payload.config.maxDepth; const currentDepth = incomingCurrentDepth || 1; diff --git a/test/fields/int.spec.ts b/test/fields/int.spec.ts index 854fde7f2c..761ee00168 100644 --- a/test/fields/int.spec.ts +++ b/test/fields/int.spec.ts @@ -1,4 +1,5 @@ import type { IndexDirection, IndexOptions } from 'mongoose'; +import { GraphQLClient } from 'graphql-request'; import { initPayloadTest } from '../helpers/configHelpers'; import { RESTClient } from '../helpers/rest'; import configPromise from '../uploads/config'; @@ -11,10 +12,14 @@ import { blocksFieldSeedData } from './collections/Blocks'; import { localizedTextValue, namedTabDefaultValue, namedTabText, tabsDoc, tabsSlug } from './collections/Tabs'; import { defaultNumber, numberDoc } from './collections/Number'; import { dateDoc } from './collections/Date'; +import type { PaginatedDocs } from '../../src/mongoose/types'; +import type { RichTextField } from './payload-types'; let client; +let graphQLClient: GraphQLClient; let serverURL; let config; +let token; describe('Fields', () => { beforeAll(async () => { @@ -22,7 +27,9 @@ describe('Fields', () => { config = await configPromise; client = new RESTClient(config, { serverURL, defaultSlug: 'point-fields' }); - await client.login(); + const graphQLURL = `${serverURL}${config.routes.api}${config.routes.graphQL}`; + graphQLClient = new GraphQLClient(graphQLURL); + token = await client.login(); }); describe('text', () => { @@ -730,5 +737,21 @@ describe('Fields', () => { expect(typeof child.doc.value.id).toBe('string'); expect(child.doc.value.items).toHaveLength(6); }); + + it('should respect rich text depth parameter', async () => { + const query = `query { + RichTextFields { + docs { + richText(depth: 2) + } + } + }`; + const response = await graphQLClient.request(query, {}, { + Authorization: `JWT ${token}`, + }); + const { docs }: PaginatedDocs = response.RichTextFields; + const uploadElement = docs[0].richText.find((el) => el.type === 'upload') as any; + expect(uploadElement.value.media.filename).toStrictEqual('payload.png'); + }); }); });