#Optimizing API Calls for Header Navigation Links Data

4 messages · Page 1 of 1 (latest)

jovial boneBOT
#

Hey people. I have a Header global to store navigation links, so naturally I have a field with a relationTo pages. Problem is when fetching Nav data from the API, I'm not sure how to filter out all the copious amounts of page data which comes along for the ride.

Sure i could run a simple map of the data to filter the relevant fields (namely page slug), but I'm worried the damage has already been done by fetching so much data from the database to begin with. Any thoughts?

The fields array in my query doesn't appear to do anything at all. It was just a test to see if could only receive the Nav title.

meager krakenBOT
#

Original message from @oak musk - Moved from #general message

wooden mirage
#

I'd suggest making a graphql query to request the shape you need. The payload website repo has a good example: https://github.com/payloadcms/website/blob/main/src/app/_graphql/globals.ts
which is fetched here: https://github.com/payloadcms/website/blob/main/src/app/_graphql/index.ts#L28

GitHub

The official Next.js website for payloadcms.com. Contribute to payloadcms/website development by creating an account on GitHub.

GitHub

The official Next.js website for payloadcms.com. Contribute to payloadcms/website development by creating an account on GitHub.