Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add result hooks #2446

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

feat: add result hooks #2446

wants to merge 2 commits into from

Conversation

GerryWilko
Copy link
Contributor

πŸ”— Linked issue

#1057

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

I have introduced a new feature result hooks. This feature is detailed in #1057.

The primary aim of this feature is to allow for augmentations to the returned type to be performed within the query builder pipeline. This allows users to use libraries like zod to assert that the schema of the returned content is valid and expected.

I feel this feature will add a more type safe way to query content and throw errors for unexpected content structure earlier in the pipeline.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Copy link

nuxt-studio bot commented Nov 23, 2023

βœ… Live Preview ready!

Name Edit Preview Latest Commit
Content Edit on Studio β†—οΈŽ View Live Preview 029bc0e

@GerryWilko
Copy link
Contributor Author

@atinux Would you or another maintainer have a chance to review this PR?

Many thanks in advance!

@atinux atinux requested a review from farnabaz December 4, 2023 15:20
@farnabaz
Copy link
Member

Can't we use await queryContent('articles').find().then(res => res.map(c => articleSchema.parse(c))) to parse contents with schema?
In current version I'd rather not to add this feature and one of core features. This is something we can consider in next major release.
Also, we will have better type support in next version and this might add more breaking change for migration.

@GerryWilko
Copy link
Contributor Author

Apologies for the delay.

So I did consider this approach however it is quite limiting in some respects. One of the lovely parts of the chainable nature of the QueryBuilder is that I can wrap up custom elements of my content query into a composable and then allow consumers of this composable to chain on more parts of the QueryBuilder to suit their needs.

If I can't hook into the resolution of the final query then it means that each consumer of the composable must do their own validation once they resolve their query. I thought this PR seemed like a reasonable addition to the queryContent composable?

@GerryWilko
Copy link
Contributor Author

@farnabaz do you have any other feedback for this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants