Skip to content

Commit

Permalink
Merge pull request #859 from saiichihashimoto/projection-from-null
Browse files Browse the repository at this point in the history
fix(groq): projection from null returns a null
  • Loading branch information
kodiakhq[bot] authored Dec 23, 2024
2 parents 3830b9e + 6aa4280 commit ad1da43
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/groq/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2327,10 +2327,12 @@ type EvaluateProjection<
TNode extends ExprNode,
TScope extends Scope<Context<any[], any>>
> = TNode extends ProjectionNode
? Evaluate<
TNode["expr"],
NestedScope<Evaluate<TNode["base"], TScope>, TScope>
>
? Evaluate<TNode["base"], TScope> extends null
? null
: Evaluate<
TNode["expr"],
NestedScope<Evaluate<TNode["base"], TScope>, TScope>
>
: never;

type EvaluateSelectAlternatives<
Expand Down
35 changes: 35 additions & 0 deletions packages/groq/src/traversal-operators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,41 @@ describe("traversal operators", () => {
>();
});

it("null{key}", async () => {
const query = "null{key}";

const tree = parse(query);

const expectedTree = {
base: { type: "Value", value: null },
expr: {
attributes: [
{
name: "key",
type: "ObjectAttributeValue",
value: { name: "key", type: "AccessAttribute" },
},
],
type: "Object",
},
type: "Projection",
} as const;

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

const result = await (await evaluate(tree)).get();

const expectedResult = null;

expect(result).toStrictEqual(expectedResult);
expectType<ExecuteQuery<typeof query>>().toStrictEqual<
WritableDeep<typeof expectedResult>
>();
});

it('[{"key":"value"}]{key}', async () => {
const query = '[{"key":"value"}]{key}';

Expand Down

0 comments on commit ad1da43

Please sign in to comment.