Typical Validation Use Cases
This document describes best practices and typical use cases for writing graph validation rules. These examples specify validation rules that can be copy/pasted into a schema.
Since most graph fields allow either a value to be entered or a link to be connected, the most common rule is a compound “oneOf” rule that includes both a “type” rule and a “numLinks” rule. The following examples mostly follow this pattern.
String field with minimum and maximum lengths
The following validation rule specifies that a field must be a string with a minimum length of 1 character and a maximum length of 20 characters or it must be connected to exactly one link that will provide the value.
Number field with minimum and maximum values
The following validation rule specifies that a field must be a number with a value between 0-1 or it must be connected to exactly one link that will provide the value.
Integer field with minimum and maximum values
The following validation rule specifies that a field must be an integer with a value between 0-255 or it must be connected to exactly one link that will provide the value.
Field that takes exactly one link
The following validation rule specifies that the field must be connected to exactly one link. A value cannot be entered for the field.
Field that takes one or more links
The following validation rule specifies that the field must be connected to exactly one or more links. A value cannot be entered for the field.
Fixed length array of integer values
The following validation rule specifies that the field must contain an array of exactly three elements, each of which must be an integer in the range 0-255. Alternatively, the field may be connected to a link that will provide the array.
Fixed length array with different element types
The following validation rule is for an array that contains three integers ranging 0-255, and an fourth value which is a number ranging from 0-1.0. Alternatively, the field may be connected to a link that will provide the array.
Last updated