lib/graphql/schema/directive/constraint.rb in graphql-schema-directive-constraint-0.2.0 vs lib/graphql/schema/directive/constraint.rb in graphql-schema-directive-constraint-0.3.0
- old
+ new
@@ -30,10 +30,16 @@
argument(:contains, String, description: "Ensure value contains", required: false)
argument(:notContains, String, description: "Ensure value does not contain", required: false)
argument(:pattern, String, description: "Ensure value matches regex, e.g. alphanumeric", required: false)
argument(:format, String, description: "Ensure value is in a particular format", required: false)
+ argument(:min, Integer, description: "Ensure value is greater than or equal to", required: false)
+ argument(:max, Integer, description: "Ensure value is less than or equal to", required: false)
+ argument(:exclusiveMin, Integer, description: "Ensure value is greater than", required: false)
+ argument(:exclusiveMax, Integer, description: "Ensure value is less than", required: false)
+ argument(:multipleOf, Integer, description: "Ensure value is a multiple", required: false)
+
argument(:without_validator, Boolean, description: "Use constraint directive without validator", required: false)
locations(
GraphQL::Schema::Directive::INPUT_FIELD_DEFINITION,
GraphQL::Schema::Directive::FIELD_DEFINITION,
@@ -51,9 +57,17 @@
owner.validates({ length: { minimum: minLength } })
in [:maxLength, maxLength]
owner.validates({ length: { maximum: maxLength } })
in [:pattern, pattern]
owner.validates({ format: { with: pattern } })
+ in [:min, min]
+ owner.validates({ numericality: { greater_than_or_equal_to: min } })
+ in [:max, max]
+ owner.validates({ numericality: { less_than_or_equal_to: max } })
+ in [:exclusiveMin, exclusiveMin]
+ owner.validates({ numericality: { greater_than: exclusiveMin } })
+ in [:exclusiveMax, exclusiveMax]
+ owner.validates({ numericality: { less_than: exclusiveMax } })
else
raise NotImplementedError("Given arguments are not implemented yet")
end
end
end