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

groq-builder: use q.infer() syntax #258

Merged
merged 3 commits into from
Jan 26, 2024
Merged

groq-builder: use q.infer() syntax #258

merged 3 commits into from
Jan 26, 2024

Conversation

scottrippey
Copy link
Member

@scottrippey scottrippey commented Jan 23, 2024

What

Previously, there were actually 3 ways we can bypass validation and infer the result type:

q.project({
  name: true,
  name2: "name",
  name3: q.field("name"),
})

However, it's really hard to understand that this syntax results in bypassing runtime validation. Instead, this PR adds the q.infer() method, which can be used in place of validation methods like q.string(). Using q.infer() is the only way to bypass runtime validation. Example:

q.project({
  name: q.infer(),
  name2: ["name", q.infer()],
  name3: q.field("name", q.infer()),
});

Benefits:

  • Makes it easier to see when runtime validation is bypassed
  • Easier to document this behavior, by documenting q.infer() instead of documenting these 3 different syntaxes
  • Teams can use an eslint rule to prevent q.infer(), if they want to enforce 100% runtime validation

Drawbacks:

  • More verbose, if your project doesn't use runtime validation

Copy link

vercel bot commented Jan 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
groqd ⬜️ Ignored (Inspect) Visit Preview Jan 25, 2024 5:32am

@scottrippey scottrippey marked this pull request as ready for review January 25, 2024 21:43
@scottrippey scottrippey merged commit beb9723 into zod-again Jan 26, 2024
3 of 5 checks passed
@scottrippey scottrippey deleted the infer branch January 26, 2024 20:52
@scottrippey
Copy link
Member Author

Closing this PR. I've reverted these changes, in favor of a different approach (a validationRequired: true flag)

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.

1 participant