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: Added q.fragment implementation #250

Merged
merged 6 commits into from
Jan 10, 2024
Merged

groq-builder: Added q.fragment implementation #250

merged 6 commits into from
Jan 10, 2024

Conversation

scottrippey
Copy link
Member

@scottrippey scottrippey commented Dec 22, 2023

Implemented q.fragment method for defining reusable fragments.

Examples

Defining a fragment:

const productFragment = q.fragment<SanitySchema.Product>().project(qProduct => ({
  name: true,
  price: true,
  imageUrls: qProduct.field('images[]').deref().field('url'),
}));

type ProductFragment = InferFragmentType<typeof productFragment>;
// Evaluates to: { name: string, price: number, imageUrls: Array<string> }

Consuming a fragment

You can pass to project:

q.star.filterByType('product').project(productFragment);

You can spread inside a project:

q.star.filterByType('product').project({
  ...productFragment,
  description: true,
  category: true,
});

You can compose multiple fragments by spreading.

TODO

  • Implementation
  • Unit tests
  • Documentation

Copy link

vercel bot commented Dec 22, 2023

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 Dec 22, 2023 9:20pm

@scottrippey scottrippey marked this pull request as ready for review December 22, 2023 14:48
@scottrippey scottrippey merged commit 2b53b9f into main Jan 10, 2024
5 checks passed
@scottrippey scottrippey deleted the fragments branch January 10, 2024 19:05
@github-actions github-actions bot mentioned this pull request Jan 10, 2024
scottrippey added a commit that referenced this pull request Jan 18, 2024
* feature(conditionals): added conditional type helpers

* feature(conditionals): implemented the `conditional$` method

* feature(conditionals): implemented `conditionalByType` method

* feature(conditionals): ensure conditionals can be spread into projections

* feature(conditionals): use custom tagged types

* feature(conditionals): `filterByType` can accept multiple types

* feature(conditionals): improved handling of `indent`

* feature(conditionals): implemented conditionals

* feature(conditionals): implemented `select` method

* feature(conditionals): removed select's "callback" signature

* feature(conditionals): added type tests

* feature(conditionals): created "root projection" test

* feature(conditionals): added test for projection + validatio

* feature(conditionals): added import for select method

* feature(conditionals): use Empty for RootResult

* feature(conditionals): implemented `selectByType`

* feature(conditionals): fixed type errors

* feature(conditionals): implemented "default" parameter

* feature(conditionals): added tests for validation

* feature(conditionals): added support for non-callback signature

* feature(conditionals): added jsdocs

* feature(conditionals): changed signature for conditional projections; uses 2nd parameter

* feature(conditionals): added shape validation to assist with projection validations

* feature(conditionals): refactored `project` to utilize object shape

* groq-builder: Added `q.fragment` implementation (#250)

* feature(fragment): added `q.fragment` implementation

* feature(fragment): added tests for fragment queries

* feature(fragment): ensure we export `Fragment` and `InferFragmentType` types

* feature(fragment): added docs

* feature(validation): fixed broken import

---------

Co-authored-by: scottrippey <scott.william.rippey@gmail.com>

* feature(conditionals): added `IGroqBuilder` for easier circular references

* feature(conditionals): improve `EntriesOf`

* feature(conditionals): updated `Conditional` signature again, to ensure unique, spreadable keys

* feature(conditionals): updated implementation of `conditional$`

* feature(conditionals): added tests for conditionals within fragments

* feature(conditionals): added tests for multiple conditionals

* feature(conditionals): improved multiple-conditional intersection types

* feature(conditionals): added CONDITIONALS docs

* feature(conditionals): made `key` a configuration option

* feature(conditionals): added an "exhaustive" check for conditionals

* feature(conditionals): updated CONDITIONALS docs

* feature(conditionals): added docs on Select function

* feature(conditionals): added more examples for `q.select`

* feature(conditionals): added jsdocs for ConditionalConfig

* feature(conditionals): fixed validation error formatting

* feature(conditionals): updated conditional tests

* feature(conditionals): removed debugging code

* feature(conditionals): fixed EntriesOf implementation

* feature(conditionals): fixed type param of no-arg versions of `validation.object()` and `validation.array()`

* feature(conditionals): removed unused imports

---------

Co-authored-by: scottrippey <scott.william.rippey@gmail.com>
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