@@ -6,6 +6,7 @@ import { DateTime } from 'luxon';
6
6
import { EnhancedResource , type ID , many , type ResourceShape } from '~/common' ;
7
7
import { type ResourceMap } from '~/core' ;
8
8
import { Variable } from '../query-augmentation/condition-variables' ;
9
+ import { currentUser } from './matching' ;
9
10
10
11
type RelationshipDefinition = Record <
11
12
string ,
@@ -14,6 +15,7 @@ type RelationshipDefinition = Record<
14
15
id : Nullable < ID > | readonly ID [ ] ,
15
16
]
16
17
| Variable
18
+ | typeof currentUser
17
19
> ;
18
20
type AnyDirectionalDefinition = Partial <
19
21
Record < RelationDirection , RelationshipDefinition >
@@ -103,7 +105,9 @@ export function createRelationships<TResourceStatic extends ResourceShape<any>>(
103
105
direction : direction as RelationDirection ,
104
106
relLabel : relLabel ,
105
107
variable : ! Array . isArray ( varOrTuple )
106
- ? varOrTuple . value // For variables this is the variable's value
108
+ ? varOrTuple instanceof Variable
109
+ ? varOrTuple . value
110
+ : undefined
107
111
: Array . isArray ( varOrTuple [ 1 ] )
108
112
? `${ relLabel } ${ i } `
109
113
: relLabel ,
@@ -125,7 +129,7 @@ export function createRelationships<TResourceStatic extends ResourceShape<any>>(
125
129
const createdAt = DateTime . local ( ) ;
126
130
127
131
const returnTerms = flattened . flatMap ( ( f ) =>
128
- f . id instanceof Variable ? [ ] : f . variable ,
132
+ f . id instanceof Variable ? [ ] : f . variable ?? [ ] ,
129
133
) ;
130
134
if ( returnTerms . length === 0 ) {
131
135
// Create hash based on input to use as a unique return since a return
@@ -150,7 +154,11 @@ export function createRelationships<TResourceStatic extends ResourceShape<any>>(
150
154
sub
151
155
. match (
152
156
flattened . map ( ( { variable, nodeLabel, id } ) =>
153
- id instanceof Variable ? [ ] : [ node ( variable , nodeLabel , { id } ) ] ,
157
+ id instanceof Variable
158
+ ? [ ]
159
+ : id === currentUser
160
+ ? [ currentUser ]
161
+ : [ node ( variable , nodeLabel , { id } ) ] ,
154
162
) ,
155
163
)
156
164
. create (
0 commit comments