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

Validation configuration changes #3687

Merged
merged 8 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions .changeset/smart-vans-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@neo4j/graphql": major
"@neo4j/graphql-ogm": major
---

Validation of type definitions is now configured using the `validate` boolean option in the constructor, which defaults to `true`.
darrellwarde marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 4 additions & 15 deletions docs/modules/ROOT/pages/custom-resolvers.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ type User implements UserInterface {
}
----

The following resolvers definition would be invalid:
The following resolvers definition would cause a warning to be logged:

[source, javascript, indent=0]
----
Expand All @@ -184,7 +184,8 @@ const resolvers = {
};
----

Instead, the following resolvers definition would be required:
The following resolvers definition would silence the warning:

[source, javascript, indent=0]
----
const resolvers = {
Expand All @@ -196,16 +197,4 @@ const resolvers = {
};
----

These checks may not always be required or desirable. If this is the case, they can be disabled using the `startupValidation` config option:

[source, javascript, indent=0]
----
const neoSchema = new Neo4jGraphQL({
typeDefs,
config: {
startupValidation: {
resolvers: false
},
},
})
----
Mismatches between the resolver map and `@customResolver` directives will always be logged to the console as a warning.
83 changes: 7 additions & 76 deletions docs/modules/ROOT/pages/migration/v4-migration/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -206,28 +206,6 @@ new Neo4jGraphQL({
});
----

[[customResolver-checks]]
==== Checks for custom resolvers

Previously, if no custom resolver was specified for a `@computed` field when creating an instance of Neo4jGraphQL, no errors would be thrown when generating the schema.
However, it is likely that the lack of a custom resolver would lead to errors at runtime. It is preferable to fail fast in this case as it is easier to debug and makes it less likely that bugs will make it into production.

As a result, checks are now performed to ensure that every `@customResolver` field has a custom resolver provided. If not the library will throw an error during schema generation.

These checks may not always be required or desirable. If this is the case, they can be disabled using the new xref::migration/v4-migration.adoc#startup-validation[`startupValidation`] config option:

[source, javascript, indent=0]
----
const neoSchema = new Neo4jGraphQL({
typeDefs,
config: {
startupValidation: {
resolvers: false
},
},
})
----

==== `requires` changes

In version 4.0.0, it is now possible to require non-scalar fields. This means it is also possible to require fields on related type.
Expand Down Expand Up @@ -645,17 +623,13 @@ type Person {

In this example, there are multiple fields in the `Team` type which have the same `Person` type, the same `@relationship` type and ("PLAYS_IN") direction (IN). This is an issue when returning data from the database, as there would be no difference between `player1`, `player2` and `backupPlayers`. Selecting these fields would then return the same data.

To disable checks for duplicate relationship fields, the `noDuplicateRelationshipFields` config option should be used:
These checks can be disabled by disabling all validation in the library, however, this is not recommended unless in production with 100% confidence of type definitions input.

[source, javascript, indent=0]
----
const neoSchema = new Neo4jGraphQL({
typeDefs,
config: {
startupValidation: {
noDuplicateRelationshipFields: false,
},
},
validate: false,
});
----

Expand Down Expand Up @@ -700,63 +674,20 @@ type Actor {
[[startup-validation]]
=== Startup validation

In version 4.0.0, startup xref::migration/v4-migration.adoc#customResolver-checks[checks for custom resolvers], and checks for duplicate relationship fields have been added. As a result, a new configuration option has been added that can disable these checks.
This new option has been combined with the option to `skipValidateTypeDefs`. As a result, `skipValidateTypeDefs` will be removed and replaced by `startupValidation`.

To only disable strict type definition validation, the following config option should be used:

[source, javascript, indent=0]
----
const neoSchema = new Neo4jGraphQL({
typeDefs,
config: {
startupValidation: {
typeDefs: false
},
},
})
----

To only disable checks for custom resolvers, the following config option should be used:

[source, javascript, indent=0]
----
const neoSchema = new Neo4jGraphQL({
typeDefs,
config: {
startupValidation: {
resolvers: false
},
},
})
----
The argument `config.skipValidateTypeDefs` has been moved to the top-level of the constructor input and renamed `validate`, which defaults to `true`.

To only disable checks for duplicate relationship fields, the following config option should be used:
To disable type definition validation, the following config option should be used:

[source, javascript, indent=0]
----
const neoSchema = new Neo4jGraphQL({
typeDefs,
config: {
startupValidation: {
noDuplicateRelationshipFields: false
},
},
validate: false,
})
----


To disable all startup checks, the following config option should be used:

[source, javascript, indent=0]
----
const neoSchema = new Neo4jGraphQL({
typeDefs,
config: {
startupValidation: false,
},
})
----
If you started using the `config.startupValidation` option, this has also been rolled into the same `validate` setting for simplicity.
The `resolvers` option of this is now just a warning, and `noDuplicateRelationshipFields` is now a mandatory check rolled into `validate`.

[[opt-in-aggregation]]
=== Opt-in Aggregation
Expand Down
152 changes: 0 additions & 152 deletions docs/modules/ROOT/pages/reference/api-reference/neo4jgraphql.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,162 +29,10 @@ Accepts all of the options from https://www.graphql-tools.com/docs/generate-sche
Type: https://neo4j.com/docs/javascript-manual/current/[`Driver`]
|An instance of a Neo4j driver.

|`config` +
darrellwarde marked this conversation as resolved.
Show resolved Hide resolved
+
Type: xref::reference/api-reference/neo4jgraphql.adoc#api-reference-neo4jgraphql-input-neo4jgraphqlconfig[`Neo4jGraphQLConfig`]
|Additional Neo4j GraphQL configuration options.

|`features` +
+
Type: xref::reference/api-reference/neo4jgraphql.adoc#api-reference-neo4jgraphql-input-neo4jfeaturessettings[`Neo4jFeaturesSettings`]
|Could be used for configure/enable/disable specific features.
darrellwarde marked this conversation as resolved.
Show resolved Hide resolved

|`plugins` +
+
Type: xref::reference/api-reference/neo4jgraphql.adoc#api-reference-neo4jgraphql-input-neo4jgraphqlplugins[`Neo4jGraphQLPlugins`]
|Plugins for the Neo4j GraphQL Library.
|===

[[api-reference-neo4jgraphql-input-neo4jgraphqlconfig]]
==== `Neo4jGraphQLConfig`

|===
|Name and Type |Description

|`driverConfig` +
+
Type: xref::reference/api-reference/neo4jgraphql.adoc#api-reference-neo4jgraphql-input-neo4jgraphqlconfig-driverconfig[`DriverConfig`]
|Additional driver configuration options.

|`queryOptions` +
+
Type: xref::reference/api-reference/neo4jgraphql.adoc#api-reference-neo4jgraphql-input-neo4jgraphqlconfig-cypherqueryoptions[`CypherQueryOptions`]
|Cypher query options, see xref::troubleshooting#troubleshooting-query-tuning[Query Tuning] for more information.

|`startupValidation` +
+
Type: xref::reference/api-reference/neo4jgraphql.adoc#api-reference-neo4jgraphql-input-neo4jgraphqlconfig-StartupValidationOptions[`StartupValidationOptions`] or `boolean`
|Whether or not startup validation checks should be run. A boolean can be used to enable/disable all startup checks. Alternatively, a `StartupValidationOptions` object can be used for fine grain controls. If nothing is passed, all checks will be run.

|===

[[api-reference-neo4jgraphql-input-neo4jgraphqlconfig-driverconfig]]
===== `DriverConfig`

|===
|Name and Type |Description

|`database` +
+
Type: `string`
|The name of the database within the DBMS to connect to.

|`bookmarks` +
+
Type: `string` or `Array<string>`
|One or more bookmarks to use for the connection.
|===

[[api-reference-neo4jgraphql-input-neo4jgraphqlconfig-cypherqueryoptions]]
===== `CypherQueryOptions`

All options are enum types imported from `@neo4j/graphql`, for example:

[source, javascript, indent=0]
----
const { CypherRuntime } = require("@neo4j/graphql");
----

|===
|Name and Type |Description

|`runtime` +
+
Type: `CypherRuntime`
|Possible options: +
+
- `CypherRuntime.INTERPRETED` +
- `CypherRuntime.SLOTTED` +
- `CypherRuntime.PIPELINED`

|`planner` +
+
Type: `CypherPlanner`
|Possible options: +
+
- `CypherPlanner.COST` +
- `CypherPlanner.IDP` +
- `CypherPlanner.DP`

|`connectComponentsPlanner` +
+
Type: `CypherConnectComponentsPlanner`
|Possible options: +
+
- `CypherConnectComponentsPlanner.GREEDY` +
- `CypherConnectComponentsPlanner.IDP`

|`updateStrategy` +
+
Type: `CypherUpdateStrategy`
|Possible options: +
+
- `CypherUpdateStrategy.DEFAULT` +
- `CypherUpdateStrategy.EAGER`

|`expressionEngine` +
+
Type: `CypherExpressionEngine`
|Possible options: +
+
- `CypherExpressionEngine.DEFAULT` +
- `CypherExpressionEngine.INTERPRETED` +
- `CypherExpressionEngine.COMPILED`

|`operatorEngine` +
+
Type: `CypherOperatorEngine`
|Possible options: +
+
- `CypherOperatorEngine.DEFAULT` +
- `CypherOperatorEngine.INTERPRETED` +
- `CypherOperatorEngine.COMPILED`

|`interpretedPipesFallback` +
+
Type: `CypherInterpretedPipesFallback`
|Possible options: +
+
- `CypherInterpretedPipesFallback.DEFAULT` +
- `CypherInterpretedPipesFallback.DISABLED` +
- `CypherInterpretedPipesFallback.WHITELISTED_PLANS_ONLY` +
- `CypherInterpretedPipesFallback.ALL`

|`replan` +
+
Type: `CypherReplanning`
|Possible options: +
+
- `CypherReplanning.DEFAULT` +
- `CypherReplanning.FORCE` +
- `CypherReplanning.SKIP`
|===

[[api-reference-neo4jgraphql-input-neo4jgraphqlconfig-StartupValidationOptions]]
===== `StartupValidationOptions`

|===
|Name and Type |Description

|`typeDefs` +
+
Type: `boolean`
|Can be used to disable strict type definition validation.

|`resolvers` +
+
Type: `boolean`
|Can be used to disable checks that expected custom resolvers have been provided.
|===

[[api-reference-neo4jgraphql-input-neo4jfeaturessettings]]
Expand Down
Loading