Skip to content

Conversation

@dylan-hart
Copy link

Adds a new folderByPath(path: String!): AssetFolder query to the AssetQuery type in the GraphQL API. It allows clients to resolve a folder's ID and metadata by providing its hierarchical path (e.g. "uploads/images/2025"), which simplifies integration scenarios where asset folder IDs are not known in advance.

Specifically, our use case has been taking Microsoft Word documents and PDFs, converting them to Markdown, and using the GraphQL API to rapidly upload many pages and assets. Because we are inferring/generating page paths at runtime, we don't know the asset folder IDs unless we connect to the PostgreSQL database or observe network packets through the browser web dev tools.

@auto-assign auto-assign bot requested a review from NGPixel July 17, 2025 23:16
Comment on lines 48 to 52
for (const slug of parts) {
const folder = await WIKI.models.assetFolders.query().where({
parentId: parentId,
slug: slug
}).first()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid querying the DB on every path segment. There's already a method to get the hierarchy in 1 query:

const folderHierarchy = await WIKI.models.assetFolders.getHierarchy(args.folderId)

Your code should either use it or do something similar.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Would a single assetFolders.query() be acceptable? I'd like to use getHierarchy(), but it requires a folderId.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're fetching all folders into memory, which isn't better. See how the getHierarchy() method works. It makes a single query using the withRecursive() method, fetching only the necessary data.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored to use recursive SQL similar to getHierarchy(), starting from root and iterating downward instead of up from child/leaf. Thanks for your suggestion. Tested with PostgreSQL 15 and SQL Server 2022 (16).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants