Skip to content
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

Remove references to create option on assertIndexesAndConstraints #189

Merged
merged 1 commit into from
Oct 17, 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
23 changes: 10 additions & 13 deletions modules/ROOT/pages/directives/indexes-and-constraints.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ directive @unique(
) on FIELD_DEFINITION
----

Using this directive does not automatically ensure the existence of these constraints, and you will need to run a function on server startup.
See the section xref::/directives/indexes-and-constraints.adoc#_asserting_constraints[Asserting constraints] for details.
Using this directive does not automatically ensure the existence of these constraints, and you will need to create them manually.

=== Usage

`@unique` directives can only be used in GraphQL object types representing nodes, and they are only applicable for the "main" label for the node.
`@unique` directives can only be used in GraphQL object types representing nodes, for any label specified on them.

In the following example, a unique constraint is asserted for the label `Colour` and the property `hexadecimal`:

Expand Down Expand Up @@ -53,7 +52,7 @@ type Colour @node(labels: ["Color"]) {
----

In the following example, all labels specified in the `labels` argument of the `@node` directive are also checked when asserting constraints.
If there is a unique constraint specified for the `hexadecimal` property of nodes with the `Hue` label, but not the `Color` label, no error is thrown and no new constraints are created when running `assertIndexesAndConstraints`.
If there is a unique constraint specified for the `hexadecimal` property of nodes with the `Hue` label, but not the `Color` label, no error is thrown when running `assertIndexesAndConstraints`.

[source, graphql, indent=0]
----
Expand All @@ -64,7 +63,7 @@ type Colour @node(labels: ["Color", "Hue"]) {

== Fulltext indexes

You can use the `@fulltext` directive to add a https://neo4j.com/docs/cypher-manual/current/indexes-for-full-text-search/[Full text index] inside Neo4j.
You can use the `@fulltext` directive to specify a https://neo4j.com/docs/cypher-manual/current/indexes-for-full-text-search/[full-text index] inside Neo4j.
For example:

[source, graphql, indent=0]
Expand All @@ -82,13 +81,12 @@ directive @fulltext(indexes: [FullTextInput]!) on OBJECT
----

Using this directive does not automatically ensure the existence of these indexes.
You need to run a function on server startup.
See the section xref::/directives/indexes-and-constraints.adoc#_asserting_constraints[Asserting constraints] for details.
They must be created manually.

=== Specifying

The `@fulltext` directive can be used on nodes.
In this example, a `Fulltext` index called "ProductName", for the name `field`, on the `Product` node, is added:
In this example, a full-text index called "ProductName", for the name `field`, on the `Product` node, is specified:

[source, graphql, indent=0]
----
Expand All @@ -98,7 +96,7 @@ type Product @fulltext(indexes: [{ indexName: "ProductName", fields: ["name"] }]
}
----

When you run xref::/directives/indexes-and-constraints.adoc#_asserting_constraints[Asserting constraints], they create the index like so:
This index can be created in the database by running the following Cypher:

[source, cypher, indent=0]
----
Expand Down Expand Up @@ -224,8 +222,8 @@ query {
== Asserting constraints

In order to ensure that the specified constraints exist in the database, you need to run the function `assertIndexesAndConstraints`.
A simple example to create the necessary constraints might look like the following, assuming a valid driver instance in the variable `driver`.
This creates two constraints, one for each field decorated with `@id` and `@unique`, and apply the indexes specified in `@fulltext`:
A simple example to check for the existence of the necessary constraints might look like the following, assuming a valid driver instance in the variable `driver`.
This checks for the unique node property constraint for the field decorated `@unique`, and checks for the index specified in `@fulltext`:

[source, javascript, indent=0]
----
Expand All @@ -245,10 +243,9 @@ const neoSchema = new Neo4jGraphQL({ typeDefs, driver });

const schema = await neoSchema.getSchema();

await neoSchema.assertIndexesAndConstraints({ options: { create: true }});
await neoSchema.assertIndexesAndConstraints();
----


:description: Directives related to generative AI in the Neo4j GraphQL Library.

[role=label--beta]
Expand Down