Skip to content

Commit 6a290e3

Browse files
authored
Merge pull request #6589 from neo4j/6585-populatedBy-bug-in-nested-create
Fix #6585
2 parents 5f5076d + 36bc7fc commit 6a290e3

File tree

7 files changed

+511
-39
lines changed

7 files changed

+511
-39
lines changed

.changeset/yellow-kiwis-go.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@neo4j/graphql": patch
3+
---
4+
5+
Fix regression on `@populatedBy` where nested create operations don't trigger callbacks

packages/graphql/src/translate/queryAST/ast/input-fields/TimestampField.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,11 @@ export class TimestampField extends InputField {
3030
super(name, attachedTo);
3131
this.attribute = attribute;
3232
}
33+
3334
public getChildren() {
3435
return [];
3536
}
3637

37-
public print(): string {
38-
return `${super.print()} <${this.name}>`;
39-
}
40-
4138
public getSetParams(queryASTContext: QueryASTContext<Cypher.Node>): Cypher.SetParam[] {
4239
const target = this.getTarget(queryASTContext);
4340
const relatedCypherExpression = this.GetFunctionForTemporalType(

packages/graphql/src/translate/queryAST/factory/Operations/CreateFactory.ts

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ export class CreateFactory {
388388
create,
389389
input,
390390
callbackBucket,
391-
isNested,
392391
relationship,
393392
});
394393
}
@@ -460,42 +459,40 @@ export class CreateFactory {
460459
create,
461460
input,
462461
callbackBucket,
463-
isNested,
464462
relationship,
465463
}: {
466464
entity: ConcreteEntityAdapter;
467465
create: CreateOperation;
468466
input: Record<string, any>;
469467
callbackBucket: CallbackBucket;
470-
isNested: boolean;
471468
relationship?: RelationshipAdapter;
472469
}) {
473-
if (!isNested) {
474-
entity.getPopulatedByFields("CREATE").forEach((attribute) => {
475-
const attachedTo = "node";
476-
// the param value it's irrelevant as it will be overwritten by the callback function
477-
const callbackParam = new Cypher.Param("1234");
478-
const field = new ParamInputField({
479-
attribute,
480-
attachedTo,
481-
inputValue: callbackParam,
482-
});
483-
create.addField(field);
470+
entity.getPopulatedByFields("CREATE").forEach((attribute) => {
471+
const attachedTo = "node";
472+
// the param value it's irrelevant as it will be overwritten by the callback function
473+
const callbackParam = new Cypher.Param("1234");
474+
const field = new ParamInputField({
475+
attribute,
476+
attachedTo,
477+
inputValue: callbackParam,
478+
});
479+
create.addField(field);
484480

485-
const callbackFunctionName = attribute.annotations.populatedBy?.callback;
486-
if (!callbackFunctionName) {
487-
throw new Error(`PopulatedBy callback not found for attribute ${attribute.name}`);
488-
}
481+
const callbackFunctionName = attribute.annotations.populatedBy?.callback;
482+
if (!callbackFunctionName) {
483+
throw new Error(`PopulatedBy callback not found for attribute ${attribute.name}`);
484+
}
489485

490-
callbackBucket.addCallback({
491-
functionName: callbackFunctionName,
492-
param: callbackParam,
493-
parent: input,
494-
type: attribute.type,
495-
});
486+
callbackBucket.addCallback({
487+
functionName: callbackFunctionName,
488+
param: callbackParam,
489+
parent: input,
490+
type: attribute.type,
496491
});
497-
} else {
498-
relationship?.getPopulatedByFields("CREATE").forEach((attribute) => {
492+
});
493+
494+
if (relationship) {
495+
relationship.getPopulatedByFields("CREATE").forEach((attribute) => {
499496
const attachedTo = "relationship";
500497
// the param value it's irrelevant as it will be overwritten by the callback function
501498
const relCallbackParam = new Cypher.Param("");

0 commit comments

Comments
 (0)