Depth issue

default discord avatar
wmcmorrow2
2 months ago
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
    60pfennig
    2 months ago

    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
    wmcmorrow2
    2 months ago

    @60pfennig You're exactly right. Thanks!!

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.