[WIP] Add support of nested logical combinators (fix #8)#11
[WIP] Add support of nested logical combinators (fix #8)#11FluorescentHallucinogen wants to merge 10 commits intovsimko:masterfrom
Conversation
|
@vsimko Need your help. I'm stuck on Could you please help implement them? 🙏 And I'll do the rest of the dirty work: updating tests, docs, etc.? 😉 |
|
(at least the build is passing tests now) type Query {
createUser (
id: ID!
name: String! @constraint(minLength: 5, maxLength: 40)
bio: String @constraint(
where: {
OR: [{
AND: [{
startsWith: "foo"
}, {
endsWith: "bar"
}]
}, {
contains: "baz"
}]
}
)
): User
}It would be nice to:
The current implementation needs to be completely changed. |
The @constraint(
where: {
OR: [{
AND: [{
startsWith: "foo"
}, {
endsWith: "bar"
}]
}, {
contains: "baz"
}]
}
)is equivalent to @constraint(
where: {
OR: [{
startsWith: "foo",
endsWith: "bar"
}, {
contains: "baz"
}]
}
) |
|
These lines need to be re-implemented using recursion: mapObjIndexed((cVal, cName) =>
validationCallback({ argName, cName, cVal, data: valueToValidate })
)The error messages collected from nested logical operators need to be flattened. What should happen with errors:
|
(yet to be implemented)
Not sure if this is possible (for nested logical combinators) due to the limitations of GraphQL schema syntax. Need to research. |
Could you please do that? I'm not sure I can do it in a reasonable time. |
Done. I've figured out. 😉 The current syntax is: @constraint(
OR: [{
startsWith: "foo",
endsWith: "bar"
}, {
contains: "baz"
}]
) |
|
Hey let's merge this :) |
|
I would like to merge it, but a test is failing. |
|
@thelinuxlich This #11 (comment) part is still not done. So this PR isn't ready for merge. |
This pull request adds support of nested logical combinators
OR,ANDandNOTto create an arbitrary logical combination of validators:The syntax is the same as used in Prisma: https://www.prisma.io/docs/prisma-graphql-api/reference/queries-qwe1/#combining-multiple-filters.