From b51cff078110f18cc1989518f3f7bd1a0f9f5f66 Mon Sep 17 00:00:00 2001 From: Darrell Warde Date: Mon, 14 Oct 2024 17:22:04 +0100 Subject: [PATCH] Remove references to `create` option on `assertIndexesAndConstraints` --- .../directives/indexes-and-constraints.adoc | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/modules/ROOT/pages/directives/indexes-and-constraints.adoc b/modules/ROOT/pages/directives/indexes-and-constraints.adoc index 9cdbafd5..39273de6 100644 --- a/modules/ROOT/pages/directives/indexes-and-constraints.adoc +++ b/modules/ROOT/pages/directives/indexes-and-constraints.adoc @@ -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`: @@ -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] ---- @@ -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] @@ -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] ---- @@ -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] ---- @@ -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] ---- @@ -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]