FormidableLabs / groqd

A schema-unaware, runtime and type-safe query builder for GROQ.
https://commerce.nearform.com/open-source/groqd
MIT License
221 stars 17 forks source link

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

Closed scottrippey closed 5 months ago

scottrippey commented 5 months ago

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:

Drawbacks:

vercel[bot] commented 5 months ago

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

1 Ignored Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **groqd** | ⬜️ Ignored ([Inspect](https://vercel.com/formidable-labs/groqd/46rcqEiChKnsnjpShC1FmvbnLZuS)) | [Visit Preview](https://groqd-git-infer-formidable-labs.vercel.app) | | Jan 25, 2024 5:32am |
scottrippey commented 5 months ago

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