-
-
Notifications
You must be signed in to change notification settings - Fork 439
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
Better alternative for @whereConditions/@orderBy #1782
Comments
I like the idea of nesting the operator and value within an input object equal to the field name, that does indeed allow for better type safety. I can see us adding something like that to Lighthouse, but in the form you currently implemented it does have a problem: there is a name collision for fields named I am curious if you managed to do negation of nested condtitionals, e.g. |
Thank you for your feedback.
Yes, this is a known limitation and, unfortunately, I don't know how to avoid this conflict. Maybe a directive like
Yep, you just need
I'm actually not sure about the enum. I added it because
looks very confusing. |
I think the potential for a naming conflict is very low, we could just accept that for ergonomic reasons. The operators Lighthouse already has ( Concerning input WhereConditions {
NOT: WhereConditions
# vs.
NOT: Boolean = false
} |
About
This will make it more consistent with
After the change, Still not sure about
because from my point of view:
a bit hard to understand. |
How about: enum Is {
NULL
NOT_NULL
} |
Mmm... Not sure, because this will break the "one operator = one property = one action" rule)
Anyway, your variant also will be possible with a custom Operator :)
Updated, but it is more complicated than I expected and still needs some work/refactor for Composite operator (relation), will continue on this weekend. Current structure (not yet pushed anywhere): """
Conditions for the related objects (`has()`) for input Nested.
See also:
* https://laravel.com/docs/8.x/eloquent-relationships#querying-relationship-existence
* https://laravel.com/docs/8.x/eloquent-relationships#querying-relationship-absence
"""
input SearchByComplexRelationNested {
# Used as marker for ComplexOperator
relation: SearchByFlag! = yes
# Conditions for related objects
where: SearchByConditionNested
# Conditions for count
count: SearchByScalarInt
"""
Shortcut for `doesntHave()`, same as:
\```
where: [...]
count: {
lt: 1
}
\```
"""
not: Boolean! = false
}
"""
Available conditions for input Nested (only one property allowed at a time).
"""
input SearchByConditionNested {
"""All of the conditions must be true."""
allOf: [SearchByConditionNested!]
"""Any of the conditions must be true."""
anyOf: [SearchByConditionNested!]
"""Not."""
not: SearchByConditionNested
"""Property condition."""
value: SearchByScalarStringOrNull
} |
Still in WIP state... The good news:
What is left:
Also about
|
Finally, it released 🎉
Documentations: https://github.com/LastDragon-ru/lara-asp/blob/master/packages/graphql/README.md |
Meanwhile
🤗 |
Breaking News: Also there few breaking changes in
Full changelog: https://github.com/LastDragon-ru/lara-asp/releases/tag/0.7.0 |
Latest news 🥳
# Schema
type Query {
"input will be generated automatically 😛"
comments(order: _ @sortBy): [Comment!]! @all
}
type Comment {
text: String
}
# Result
type Query {
"""input will be generated automatically 😛"""
comments(order: [SortByClauseComment!]): [Comment!]!
}
"""Sort clause for type Comment (only one property allowed at a time)."""
input SortByClauseComment {
"""Property clause."""
text: SortByDirection
} Full changelog: https://github.com/LastDragon-ru/lara-asp/releases/tag/0.9.0 |
@LastDragon-ru I like this allot ;) is it possible to integrate this into Lighthouse, or are there additional requirements to meet @spawnia objections/ vision? |
@MrGekko thanks :) Would be good to integrate it, but lighthouse requires |
The next major version of Lighthouse will probably be PHP 7.4+, so we won't be able to do a copy-paste integration anytime soon. I am happy to let @LastDragon-ru experiment with an improved API though, perhaps it can make its way into Lighthouse at some point. |
Since 0.14.0 the |
Finaly, v1.0.0 is released. It is more about huge refactoring to have operator directives instead of list of classes and for future changes (as I've mentioned in #1782 (comment)), but also added support of bitwise operators support ( |
v2.0.0 is here 🥳 The major changes are:
Please see full release note and documentation for more details. Please also note that minimal version of Lighthouse set to "^5.68.0". |
is there any hope to see this inside mainstream lighthouse? |
The new version with Lighthouse v6 support is released! 🎉 About merging inside Lighthouse: looks like PHP and Laravel versions are the same now, but the package depends from few other packages -> it is not possible just copy it into Lighthouse -> a lot of work required. I have no time to work on it, unfortunately. There is also some chance that API may be changed a bit (eg it is definitely required for complexity calculation, and maybe for json support). |
The first version was released almost 3 years ago, and today the v6.2.0 with Laravel v11 support is released 🎉 The v6 finally solved collision between fields names and operators names - fields moved into # Old
users(
where: {
name: { equal: "..." }
}
) { ... }
# New
users(
where: {
field: {
name: { equal: "..." }
}
}
) { ... } Footnotes
|
Any updates on when/if this will make it into Lighthouse? |
To be honest, I'm not sure that it will happen anytime soon. Since the first versions there were a lot of changes, code base growth significantly, more external dependencies added (including my other packages), etc. This is a huge work. I have no time for that 🤷♂️ Why not just use my package? 🤗 |
I'm tried to use the existing
@whereConditions
, unfortunately, I very fast found that it is a bit strange and doesn't allow you to control available relations and their properties + it usesMixed
type that makes queries unsafe (eg "string < 10" probably is an error). Initially, I wanted to create a PR with fixes, but I carried away and created two new directives instead 😁Will be glad for any feedback :)
@searchBy
That's all, just search 😃
@sortBy
Very close to
@orderBy
but in addition allows using HasOne/BelongTo relations for ordering 😊The text was updated successfully, but these errors were encountered: