Skip to content

Commit c936780

Browse files
authored
Merge pull request #155 from darrellwarde/populated-by-locations
Fixes for `@populatedBy` documentation
2 parents cdb05c4 + c5304d6 commit c936780

File tree

1 file changed

+3
-52
lines changed

1 file changed

+3
-52
lines changed

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

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ to populate fields which have not been provided within the input.
504504

505505
For non-required values, callbacks may return `undefined` (meaning that nothing is changed or added to the property) or `null` (meaning that the property will be removed).
506506

507+
The `@populatedBy` directive can only be used on scalar fields.
508+
507509
=== Definition
508510

509511
[source, graphql, indent=0]
@@ -555,7 +557,7 @@ new Neo4jGraphQL({
555557
})
556558
----
557559

558-
== Context values
560+
=== Context values
559561

560562
The GraphQL context for the request is available as the third argument in a callback.
561563
This maps to the argument pattern for GraphQL resolvers.
@@ -592,54 +594,3 @@ new Neo4jGraphQL({
592594
----
593595

594596
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.
595-
596-
=== Definition
597-
598-
[source, graphql, indent=0]
599-
----
600-
enum CallbackOperation {
601-
CREATE
602-
UPDATE
603-
}
604-
605-
"""Instructs @neo4j/graphql to invoke the specified callback function when updating or creating the properties on a node or relationship."""
606-
directive @callback(
607-
"""Which events to invoke the callback on."""
608-
operations: [CallbackOperation!]! = [CREATE, UPDATE]
609-
"""The name of the callback function."""
610-
name: String!
611-
) on FIELD_DEFINITION
612-
----
613-
614-
=== Usage
615-
616-
Type definitions:
617-
618-
[source, graphql, indent=0]
619-
----
620-
type Product {
621-
name: String!
622-
slug: String! @callback(operations: [CREATE, UPDATE], name: "slug")
623-
}
624-
----
625-
626-
Schema construction (note that the callback is asynchronous):
627-
628-
[source, javascript, indent=0]
629-
----
630-
const slugCallback = async (root) => {
631-
return `${root.name}_slug`
632-
}
633-
634-
new Neo4jGraphQL({
635-
typeDefs,
636-
driver,
637-
features: {
638-
populatedBy: {
639-
callbacks: {
640-
slug: slugCallback
641-
}
642-
}
643-
}
644-
})
645-
----

0 commit comments

Comments
 (0)