Skip to content

Commit

Permalink
fix: named inputs as lhs expression operand (#1287)
Browse files Browse the repository at this point in the history
* fix: named inputs as lhs expression operand

* chore: fixes
  • Loading branch information
davenewza authored Nov 9, 2023
1 parent c18f8df commit bad329e
Show file tree
Hide file tree
Showing 7 changed files with 443 additions and 29 deletions.
14 changes: 14 additions & 0 deletions integration/testdata/operation_list_where_explicit/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ test("List Where filters - using equal operator (string) - filters correctly", a
expect(results[0].title).toEqual("Fred");
});

test("List Where filters inverse - using equal operator (string) - filters correctly", async () => {
await actions.createPost({ title: "Fred" });
await actions.createPost({ title: "NotFred" });

const { results } = await actions.listPostsEqualStringInverse({
where: {
whereArg: "Fred",
},
});

expect(results.length).toEqual(1);
expect(results[0].title).toEqual("Fred");
});

test("List Where filters - using not equal operator (string) - filters correctly", async () => {
await actions.createPost({ title: "Fred" });
await actions.createPost({ title: "NotFred" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ model Post {
list listPostsEqualString(whereArg: Text) {
@where(post.title == whereArg)
}
list listPostsEqualStringInverse(whereArg: Text) {
@where(whereArg == post.title)
}
list listPostsNotEqualString(whereArg: Text) {
@where(post.title != whereArg)
}
Expand Down
Binary file added schema/__debug_bin947378542
Binary file not shown.
9 changes: 1 addition & 8 deletions schema/expressions/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,8 @@ func applyAdditionalOperandScopes(asts []*parser.AST, scope *ExpressionScope, co
switch attribute.Name.Value {
case parser.AttributePermission:
// no inputs allowed in permissions
case parser.AttributeValidate:
if position == OperandPositionLhs {
scope = applyInputsInScope(asts, context, scope)
}
default:
// todo: is this correct?
if position == OperandPositionRhs {
scope = applyInputsInScope(asts, context, scope)
}
scope = applyInputsInScope(asts, context, scope)
}

return scope.Merge(additionalScope)
Expand Down
Loading

0 comments on commit bad329e

Please sign in to comment.