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

Projection or ArrayPostfix on nullable array #642

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
ed94ef0
test for #641
saiichihashimoto Jan 20, 2024
e33cecf
Merge branch 'main' into 641-hidden-field-property-is-not-respected-a…
saiichihashimoto Jan 24, 2024
d379381
Merge branch 'main' into 641-hidden-field-property-is-not-respected-a…
saiichihashimoto Jan 24, 2024
a6fcc91
Merge branch 'main' into 641-hidden-field-property-is-not-respected-a…
saiichihashimoto Jan 25, 2024
ad0af73
Merge branch 'main' into 641-hidden-field-property-is-not-respected-a…
saiichihashimoto Jan 25, 2024
02374b5
Merge branch 'main' into 641-hidden-field-property-is-not-respected-a…
saiichihashimoto Jan 25, 2024
cac3000
Merge branch 'main' into 641-hidden-field-property-is-not-respected-a…
saiichihashimoto Jan 25, 2024
4355db0
Merge branch 'main' into 641-hidden-field-property-is-not-respected-a…
saiichihashimoto Jan 29, 2024
ed2a37f
Merge branch 'main' into 641-hidden-field-property-is-not-respected-a…
saiichihashimoto Jan 29, 2024
ef89c6b
Merge branch 'main' into 641-hidden-field-property-is-not-respected-a…
saiichihashimoto Jan 30, 2024
42d752d
Merge branch 'main' into 641-hidden-field-property-is-not-respected-a…
saiichihashimoto Feb 1, 2024
4e31100
Merge branch 'main' into 641-hidden-field-property-is-not-respected-a…
saiichihashimoto May 15, 2024
81ef100
Merge branch 'main' into 641-hidden-field-property-is-not-respected-a…
saiichihashimoto Oct 18, 2024
427df42
Merge branch 'main' into 641-hidden-field-property-is-not-respected-a…
saiichihashimoto Oct 29, 2024
6718e5d
Merge branch 'main' into 641-hidden-field-property-is-not-respected-a…
saiichihashimoto Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 201 additions & 0 deletions packages/groq/src/specific-issues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import { expectType } from "@saiichihashimoto/test-utils";
import { evaluate, parse } from "groq-js";
import type { WritableDeep } from "type-fest";

import {
defineArrayMember,
defineConfig,
defineField,
defineType,
} from "@sanity-typed/types";
import type { InferSchemaValues } from "@sanity-typed/types";

import type { ExecuteQuery, Parse } from ".";
import type { ScopeFromPartialContext } from "./internal";

Expand Down Expand Up @@ -95,4 +103,197 @@ describe("specific issues", () => {
>
>().toStrictEqual<WritableDeep<typeof expectedResult>>();
});

it("#641 FIXME", async () => {
// https://github.com/saiichihashimoto/sanity-typed/issues/641
const query = `
*[_type == "foo" && type == "links"]{
_id,
title,
links[]{
_key,
title,
url,
target
}
}
`;

const tree = parse(query);

const expectedTree = {
base: {
base: { type: "Everything" },
expr: {
left: {
left: { name: "_type", type: "AccessAttribute" },
op: "==",
right: { type: "Value", value: "foo" },
type: "OpCall",
},
right: {
left: { name: "type", type: "AccessAttribute" },
op: "==",
right: { type: "Value", value: "links" },
type: "OpCall",
},
type: "And",
},
type: "Filter",
},
expr: {
base: { type: "This" },
expr: {
attributes: [
{
name: "_id",
type: "ObjectAttributeValue",
value: { name: "_id", type: "AccessAttribute" },
},
{
name: "title",
type: "ObjectAttributeValue",
value: { name: "title", type: "AccessAttribute" },
},
{
name: "links",
type: "ObjectAttributeValue",
value: {
base: {
base: { name: "links", type: "AccessAttribute" },
type: "ArrayCoerce",
},
expr: {
base: { type: "This" },
expr: {
attributes: [
{
name: "_key",
type: "ObjectAttributeValue",
value: { name: "_key", type: "AccessAttribute" },
},
{
name: "title",
type: "ObjectAttributeValue",
value: { name: "title", type: "AccessAttribute" },
},
{
name: "url",
type: "ObjectAttributeValue",
value: { name: "url", type: "AccessAttribute" },
},
{
name: "target",
type: "ObjectAttributeValue",
value: { name: "target", type: "AccessAttribute" },
},
],
type: "Object",
},
type: "Projection",
},
type: "Map",
},
},
],
type: "Object",
},
type: "Projection",
},
type: "Map",
} as const;

expect(tree).toStrictEqual(expectedTree);
expectType<Parse<typeof query>>().toStrictEqual<
WritableDeep<typeof expectedTree>
>();

const config = defineConfig({
dataset: "dataset",
projectId: "projectId",
schema: {
types: [
defineType({
name: "foo",
type: "document",
fields: [
defineField({
name: "type",
type: "string",
options: {
list: [
{ title: "About", value: "about" },
{ title: "Social", value: "social" },
{ title: "Links", value: "links" },
],
},
validation: (Rule) => Rule.required(),
}),
defineField({
name: "title",
type: "string",
validation: (Rule) => Rule.required(),
}),
defineField({
name: "links",
type: "array",
of: [
defineArrayMember({
type: "object",
fields: [
defineField({
name: "title",
type: "string",
}),
defineField({
name: "url",
type: "string",
}),
defineField({
name: "target",
type: "string",
options: {
list: [
{ title: "Self", value: "_self" },
{ title: "Blank", value: "_blank" },
],
},
}),
],
}),
],
}),
],
}),
],
},
});

const dataset: InferSchemaValues<typeof config>["foo"][] = [];

const result = await (await evaluate(tree, { dataset })).get();

const expectedResult = [] as {
_id: string;
links:
| {
_key: string;
target: "_blank" | "_self" | null;
title: string | null;
url: string | null;
}[]
| null;
title: string;
}[];

expect(result).toStrictEqual(expectedResult);
expectType<
ExecuteQuery<
typeof query,
ScopeFromPartialContext<{
dataset: WritableDeep<typeof dataset>;
}>
>
>().toStrictEqual<WritableDeep<typeof expectedResult>>();
});
});
2 changes: 1 addition & 1 deletion packages/types/src/specific-issues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe("specific issues", () => {
}>();
});

it("#589 object -> array -> block -> object -> field", async () => {
it("#589 object -> array -> block -> object -> field", () => {
const config = defineConfig({
dataset: "dataset",
projectId: "projectId",
Expand Down
Loading