Skip to content

WIP: added q.contentBlocks utility - #375

Draft
scottrippey wants to merge 15 commits into
mainfrom
content-blocks
Draft

scottrippey wants to merge 15 commits into
mainfrom
content-blocks

Conversation

@scottrippey

@scottrippey scottrippey commented Apr 14, 2025 •

Copy link
Copy Markdown
Contributor

Feature:

  • Adds the helpers q.customBlock() and q.customBlocks()

Bug fixes:

  • If selecting a an array field directly, any custom parser given to the field method will parse the array instead of objects on the array.
  • If a custom parser is given to an "..." projection, that parser's type will now be in the result, instead of ignored.

@changeset-bot

changeset-bot Bot commented Apr 14, 2025 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 83c6c20

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Apr 14, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
groqd Ready Ready Preview Dec 4, 2026 5:08pm UTC

Request Review

@scottrippey scottrippey changed the title WIP added q.contentBlocks utility WIP: added q.contentBlocks utility Apr 14, 2025
@scottrippey scottrippey mentioned this pull request Jun 17, 2025
2 tasks done
@Rhym

Rhym commented Nov 14, 2025

Copy link
Copy Markdown

@scottrippey Hey mate, just wanted to say this would be a great feature to have in the package! Thanks for your hard work.

@scottrippey

Copy link
Copy Markdown
Contributor Author

@Rhym I don't currently have the resources to work on this PR, but I'd be happy to accept contributions if you're able.

@Rhym

Rhym commented Nov 14, 2025 •

Copy link
Copy Markdown

Thanks for the reply, @scottrippey . I fully understand. If possible, I just have one issue left with my migration. I can't for the life of me figure out how to split the content here into a fragment for reuse. I have tried so many different ways, and it just doesn't like it:

import { runQuery } from "@/lib/sanity";

import { q, type InferFragmentType } from "./groqd-client";
import { linkExternalFragment } from "./fragments/link-external";
import { linkInternalFragment } from "./fragments/link-internal";

const fragment = q.fragmentForType<"contactPage">().project((sub) => ({
  title: true,
  ogTitle: true,
  ogDescription: true,
  content: sub.field("content[]").project((contentSub) => ({
    "...": true,
    markDefs: contentSub.field("markDefs[]").project((markDefsSub) => ({
      "...": true,
      ...markDefsSub.conditionalByType({
        "annotation.link": {
          _type: true,
          _key: true,
          links: markDefsSub
            .field("links[]")
            .project((linksSub) => ({
              ...linksSub.conditionalByType({
                linkInternal: linkInternalFragment,
                linkExternal: linkExternalFragment,
              }),
            }))
            .slice(0),
        },
      }),
    })),
  })),
}));

export type SanityContactPage = InferFragmentType<typeof fragment>;

export const getContactPageQuery = () =>
  runQuery(q.star.filterByType("contactPage").slice(0).project(fragment), {});

…tead of assuming the parser is for the objects in the array
…n inferring type, and also the q.contentBlock helper should be able to be used with an ellipsis property
… the output of that parser in the output type.
Comment on lines +82 to +83
: TProjectionMap extends { "...": Parser }
? InferParserOutput<TProjectionMap["..."]>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This allows ellipsis parsers to return their type instead of being skipped. It's because Parser<TResultItem, infer TOutput> is too specific and gets skipped.

This branch was successfully deployed

1 active deployment
Preview — 83c6c20f Deployed Dec 4, 2026 by vercel[bot]
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.

3 participants