Add support of logical operations
In current implementation rules inside @constraint directive are combined by logical (boolean) AND:
input BookInput {
title: String! @constraint(minLength: 5, format: "email")
}
Custom directives in GraphQL are also combined by AND:
input BookInput {
title: String! @constraint(minLength: 5) @constraint(format: "email")
}
What about adding support of logic operations (AND, OR and NOT) for nest rules (similar to https://github.com/maticzav/graphql-shield#and-or-not)? Something like (the syntax is subject to discussion):
@constraint("or(multipleOf: 7, multipleOf: 11)")
or
@constraint(OR: [multipleOf: 7, multipleOf: 11])
Open for discussion on the or syntax. What example scenarios do you see not covering?
What example scenarios do you see
notcovering?
E.g.:
@constraint("not(multipleOf: 3)")
or
@constraint("not(startsWith: 'foo')")
or
@constraint("not(endsWith: 'foo')")
Moreover, implementing not makes many rules like notContains unnecessary in favor of not + contains.
Open for discussion on the
orsyntax.
I propose the syntax similar to the syntax that is used in Prisma: https://www.prisma.io/docs/prisma-graphql-api/reference/queries-qwe1/#combining-multiple-filters.
Custom directives in GraphQL are also combined by
AND:
input BookInput {
title: String! @constraint(minLength: 5) @constraint(format: "email")
}
I was wrong. According to https://facebook.github.io/graphql/June2018/#sec-Directives-Are-Unique-Per-Location, it's not possible to use more than one directive of the same name for the same location.
That's interesting, because it's definitely supported within graphql and is the current behaviour
@confuser
because it's definitely supported within graphql and is the current behaviour
See https://github.com/graphql/graphql-js/blob/master/src/validation/rules/UniqueDirectivesPerLocation.js.