#Query blocks with something like findByID

2 messages · Page 1 of 1 (latest)

hybrid needle
#

Hi all, is it possible to query specific blocks with one of the find tools?

The only method I could come up with is:

export const resolveLayout = async (obj, args: ResolverArgs, info, depth?: number) => {
    const pages = await payload.find({
        collection: "pages",
        depth: depth ?? 0,
    })

    const layouts = pages.docs.flatMap(({layout}) => layout);
    const layout = layouts.find(({id}) => id === args.layoutId)
    return layout;
}```
But it's heavy as it has to search through every single page, flatMap all the layouts and then bring back the layout that has the correct id

This example isn't 100% as it only works through the pages collection, but it would need to search all of them. I had hoped for something like:
```ts
const layout = await payload.findByID({
        id: args.layoutId,
        collection: "blocks",
        depth: depth ?? 0,
    })

return layout
mossy brambleBOT