@@ -4,18 +4,32 @@ import type * as Schema from 'effect/Schema';
44import { describe , expect , it } from 'vitest' ;
55import { translateFilterToGraphql } from '../../src/utils/translate-filter-to-graphql.js' ;
66
7+ export const User = Entity . Schema (
8+ {
9+ username : Type . String ,
10+ } ,
11+ {
12+ types : [ Id ( 'f6fa5a6a-7dbf-4c31-aba5-7b4cd0a9b2de' ) ] ,
13+ properties : {
14+ username : Id ( 'f0dfb5c0-3c90-4d30-98a3-6a139c8b5943' ) ,
15+ } ,
16+ } ,
17+ ) ;
18+
719export const Todo = Entity . Schema (
820 {
921 name : Type . String ,
1022 completed : Type . Boolean ,
1123 priority : Type . Number ,
24+ assignees : Type . Relation ( User ) ,
1225 } ,
1326 {
1427 types : [ Id ( 'a288444f-06a3-4037-9ace-66fe325864d0' ) ] ,
1528 properties : {
1629 name : Id ( 'a126ca53-0c8e-48d5-b888-82c734c38935' ) ,
1730 completed : Id ( 'd2d64cd3-a337-4784-9e30-25bea0349471' ) ,
1831 priority : Id ( 'ee920534-42ce-4113-a63b-8f3c889dd772' ) ,
32+ assignees : Id ( 'f399677c-2bf9-40c3-9622-815be7b83344' ) ,
1933 } ,
2034 } ,
2135) ;
@@ -147,6 +161,44 @@ describe('translateFilterToGraphql number filters', () => {
147161 } ) ;
148162} ) ;
149163
164+ describe ( 'translateFilterToGraphql relation filters' , ( ) => {
165+ it ( 'should translate relation `exists` filter correctly' , ( ) => {
166+ const filter : TodoFilter = {
167+ // @ts -expect-error - this is a test
168+ assignees : { exists : true } ,
169+ } ;
170+
171+ const result = translateFilterToGraphql ( filter , Todo ) ;
172+
173+ expect ( result ) . toEqual ( {
174+ relations : {
175+ some : {
176+ typeId : { is : 'f399677c-2bf9-40c3-9622-815be7b83344' } ,
177+ } ,
178+ } ,
179+ } ) ;
180+ } ) ;
181+
182+ it ( 'should translate relation `exists: false` filter correctly' , ( ) => {
183+ const filter : TodoFilter = {
184+ // @ts -expect-error - this is a test
185+ assignees : { exists : false } ,
186+ } ;
187+
188+ const result = translateFilterToGraphql ( filter , Todo ) ;
189+
190+ expect ( result ) . toEqual ( {
191+ not : {
192+ relations : {
193+ some : {
194+ typeId : { is : 'f399677c-2bf9-40c3-9622-815be7b83344' } ,
195+ } ,
196+ } ,
197+ } ,
198+ } ) ;
199+ } ) ;
200+ } ) ;
201+
150202describe ( 'translateFilterToGraphql multiple filters' , ( ) => {
151203 it ( 'should translate multiple filters correctly' , ( ) => {
152204 const filter : TodoFilter = {
0 commit comments