-
Notifications
You must be signed in to change notification settings - Fork 5
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
[WIP] Add support of nested logical combinators (fix #8) #11
base: master
Are you sure you want to change the base?
[WIP] Add support of nested logical combinators (fix #8) #11
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
,AND
andNOT
to 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.