Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Depth issue

default discord avatar
wmcmorrow2last year
2

All of my documents seem to be returned fully populated without using the depth field. I've tried to set it to 0 but I still seem to get a response a fully populated aray.



I have a request that looks like this:



export const getMyLists = () => {


return async (dispatch, getState) => {


const myProfile = getState().user.myProfile


const query = {


author: {


equals: myProfile.id,


}


};


const stringifiedQuery = qs.stringify(


{


depth: 0,


sort: 'createdAt',


where: query,


},


{ addQueryPrefix: true }


);


let myLists = []



console.log('stringifiedQuery...')


console.log(stringifiedQuery)


try {


const res = await axios.get(

${API_ENDPOINT}/lists

)


myLists = res.data.docs


} catch (error) {


console.log('AXIOS Error.....')


console.log(error);


} finally {


dispatch({


type: SET_MY_LISTS,


payload: myLists


})


return


}


}


}



It queries a collection like this:



import { Block, CollectionConfig } from "payload/types";



const Lists: CollectionConfig = {


slug: 'lists',


admin: {


useAsTitle: 'name',


},


access: {


read: () => true,


},


fields: [


{


name: 'name',


type: 'text',


required: true,


},


{


name: 'icon',


type: 'text',


},


{


name: "description",


type: "richText",


},


{


name: 'splashImage',


type: 'upload',


relationTo: 'media',


},


{


name: 'owner',


type: 'relationship',


relationTo: 'users',


required: true,


},


{


name: 'locations',


type: 'relationship',


relationTo: 'locations',


hasMany: true,


index: true,


required: true,


},


],


timestamps: false,


}


Could this be a bug?

  • default discord avatar
    60pfenniglast year

    Hey I think you forgot to add your query to your request. In your

    axios.get(...)

    make sure you add the parameters you have created.


    const fullUri = `${API_ENDPOINT}/lists${stringifiedQuery }` 
    const res = await axios.get(fullUri)
  • default discord avatar
    wmcmorrow2last year
    @306429157179392002

    You're exactly right. Thanks!!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.