Hi everyone, I'm trying to create a series of custom express endpoints for my app and have run into a hefty performance issue using the internal API. The end goal of one of my endpoints is to perform a search that could potentially return tens of thousnands of entries many of which would have some fairly large fields (PDF data) that doesn't need to be sent to the client. I couldn't find anything in the docs for how to specify a subset of fields for the internal API (apologies if I just missed that while reading the docs), so I decided to use the javascript map function to extract the data I want and discard the rest before sending the search results back to the client. Is there a good way to hit the GraphQL API from a custom express endpoint running on the same server as Payload? If not, is there a better way to send only the necessary fields back to the client?
Thank you!
Is the data highly relational or housed in a single collection? There is an open PR that allows you to "select" which fields to populate on the relationship. This could be your answer if your struggle is relationship population.
Why can't you use the built in GraphQL endpoint instead of relying on a custom endpoint to then call GraphQL?
If you don't have access control concerns to work around with your data then another option would be to use Algolia or ElasticSearch and update those from collection afterChange hooks.
Currently the data is just stored in a single collection. We're using custom endpoints for a few reasons: firstly, there's some input validation before the Payload call and other data processing happening after, both of which we want to keep on the server. Secondly there are access control concerns; the custom endpoints need to be accessed and authenticated differently than the bare Payload APIs, and as such we want to keep that authentication separate. Thirdly, custom endpoints have generally been a huge help in keeping our project organized. The overhead to create the endpoints was fairly low and is cleaned up our frontend code considerably so we'd like to stick with this paradigm as much as possible.
In any case, I just need a way to internally run a search query where the docs it returns contain a subset of the fields from the collection
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.