-
Notifications
You must be signed in to change notification settings - Fork 61
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
FIX: Don't attempt to correct sort when passed as an argument (closes #571) #577
Conversation
e8b485a
to
f2af7e0
Compare
Bump. This issue is completely breaking one of my queries |
src/Schema/Traits/SortTrait.php
Outdated
// If the sort has been passed as a variable, we can't attempt to fix it | ||
// See https://github.com/silverstripe/silverstripe-graphql/issues/573 | ||
if (!$arg->value instanceof ObjectValueNode) { | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the circumstances that result in the value not being an instance of that class?
Depending on what those circumstances are, we might want to throw an exception (or at the very least log a warning) if someone tries to perform a sort that we explicitly don't respect here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$arg->value
is only ever an instance of ObjectValueNode
when the sort order is baked into the query, so the continue
statement is reached when sort is passed as a variable instead.
fc1c090
to
bd3a8d5
Compare
@GuySartorelli a little more context: there are two ways to pass a sort order: (1) baked directly in to the query itself, or (2) as an argument. For (1), #563 was merged to ensure that the order that you provide sort fields is respected. A regression from that PR is that when you use approach (2), a warning is thrown. For (2), #563 had no effect anyway. This PR just ensures that when using this approach, the warning isn’t thrown and everything behaves as it did before #563 was merged. Ideally, we’d expand #563 to cover both approaches to sorting. However that isn’t possible, because the underlying GraphQL library discards the order that sort fields are passed in when parsing the query. That isn’t a bug with the library, it’s actually the intended behaviour as it respects the GraphQL spec. There‘s some more info in #573 about that, but that’s a much bigger job and would have to be targeted at a major release. |
Thank you for that extra context. I think in that case I'm okay with this - but a warning needs to be logged so developers can get some feedback that their query isn't working as intended. |
I’m not really sure how to tackle that, the warning is the problem... we could possibly use a custom logger and call |
We should log a warning using the
Yup, that's true of all logging. Better to give the option than nothing though. |
bd3a8d5
to
d6e7735
Compare
I’ve finally got around to this. Using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for doing this.
Description
Proposed fix for #571. Doesn’t actually solve the underlying issue, but prevents the warnings being emitted by
SortTrait
.Manual testing steps
N/A
Issues
Pull request checklist