Skip to content

Commit 4de4bea

Browse files
authored
Merge pull request #284 from neo4j/populated-by-operation
Docs on populatedByOperation
2 parents 1a1f472 + 3ffa999 commit 4de4bea

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

modules/ROOT/pages/directives/custom-logic.adoc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,4 +597,25 @@ new Neo4jGraphQL({
597597
})
598598
----
599599

600-
Note that the second positional argument, in this case `_args`, has a type of `Record<string, never>`, and as such it will always be an empty object.
600+
Note that the second positional argument, in this case `_args`, has a type of `Record<string, never>`, and as such it is always an empty object.
601+
This is to maintain a compatible signature with GraphQL resolvers.
602+
603+
604+
**`populatedByOperation`**
605+
606+
The `context` argument contains the field `populatedByOperation`.
607+
This field is the mutation type that triggered the callback (`CREATE` or `UPDATE`).
608+
`populatedByOperation` allows for different logic to be executed depending on the type of operation.
609+
For example:
610+
611+
[source, javascript, indent=0]
612+
----
613+
const modifiedByCallback = async (_parent, _args, context) => {
614+
if(context.populatedByOperation === "UPDATE"){
615+
return context.username;
616+
} else {
617+
return "";
618+
}
619+
}
620+
----
621+

0 commit comments

Comments
 (0)