Skip to content

Fixes for @populatedBy documentation #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 3 additions & 52 deletions modules/ROOT/pages/directives/custom-logic.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ to populate fields which have not been provided within the input.

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).

The `@populatedBy` directive can only be used on scalar fields.

=== Definition

[source, graphql, indent=0]
Expand Down Expand Up @@ -555,7 +557,7 @@ new Neo4jGraphQL({
})
----

== Context values
=== Context values

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

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.

=== Definition

[source, graphql, indent=0]
----
enum CallbackOperation {
CREATE
UPDATE
}

"""Instructs @neo4j/graphql to invoke the specified callback function when updating or creating the properties on a node or relationship."""
directive @callback(
"""Which events to invoke the callback on."""
operations: [CallbackOperation!]! = [CREATE, UPDATE]
"""The name of the callback function."""
name: String!
) on FIELD_DEFINITION
----

=== Usage

Type definitions:

[source, graphql, indent=0]
----
type Product {
name: String!
slug: String! @callback(operations: [CREATE, UPDATE], name: "slug")
}
----

Schema construction (note that the callback is asynchronous):

[source, javascript, indent=0]
----
const slugCallback = async (root) => {
return `${root.name}_slug`
}

new Neo4jGraphQL({
typeDefs,
driver,
features: {
populatedBy: {
callbacks: {
slug: slugCallback
}
}
}
})
----
Loading