Skip to content

Commit a90a6b7

Browse files
committed
Allow createRelationships to use currentUser
1 parent bf3b579 commit a90a6b7

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/core/database/query/create-relationships.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { DateTime } from 'luxon';
66
import { EnhancedResource, type ID, many, type ResourceShape } from '~/common';
77
import { type ResourceMap } from '~/core';
88
import { Variable } from '../query-augmentation/condition-variables';
9+
import { currentUser } from './matching';
910

1011
type RelationshipDefinition = Record<
1112
string,
@@ -14,6 +15,7 @@ type RelationshipDefinition = Record<
1415
id: Nullable<ID> | readonly ID[],
1516
]
1617
| Variable
18+
| typeof currentUser
1719
>;
1820
type AnyDirectionalDefinition = Partial<
1921
Record<RelationDirection, RelationshipDefinition>
@@ -103,7 +105,9 @@ export function createRelationships<TResourceStatic extends ResourceShape<any>>(
103105
direction: direction as RelationDirection,
104106
relLabel: relLabel,
105107
variable: !Array.isArray(varOrTuple)
106-
? varOrTuple.value // For variables this is the variable's value
108+
? varOrTuple instanceof Variable
109+
? varOrTuple.value
110+
: undefined
107111
: Array.isArray(varOrTuple[1])
108112
? `${relLabel}${i}`
109113
: relLabel,
@@ -125,7 +129,7 @@ export function createRelationships<TResourceStatic extends ResourceShape<any>>(
125129
const createdAt = DateTime.local();
126130

127131
const returnTerms = flattened.flatMap((f) =>
128-
f.id instanceof Variable ? [] : f.variable,
132+
f.id instanceof Variable ? [] : f.variable ?? [],
129133
);
130134
if (returnTerms.length === 0) {
131135
// 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>>(
150154
sub
151155
.match(
152156
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 })],
154162
),
155163
)
156164
.create(

0 commit comments

Comments
 (0)