Skip to content
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

Merged
merged 1 commit into from
May 23, 2024

Conversation

kinglozzer
Copy link
Member

@kinglozzer kinglozzer commented Feb 28, 2024

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

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
    • Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

@kinglozzer kinglozzer force-pushed the 571-sort-warning branch 2 times, most recently from e8b485a to f2af7e0 Compare March 4, 2024 15:18
@marwan38
Copy link

Bump. This issue is completely breaking one of my queries

tests/Schema/IntegrationTest.php Outdated Show resolved Hide resolved
tests/Schema/IntegrationTest.php Show resolved Hide resolved
Comment on lines 48 to 56
// 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;
}
Copy link
Member

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.

Copy link
Member Author

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.

@kinglozzer
Copy link
Member Author

@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.

@GuySartorelli
Copy link
Member

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.

@kinglozzer
Copy link
Member Author

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 $logger->info() but unless the logger is set up to actually record that somewhere, nobody will ever see it.

@GuySartorelli
Copy link
Member

GuySartorelli commented May 9, 2024

We should log a warning using the Psr\Log\LoggerInterface.errorhandler singleton documented in https://docs.silverstripe.org/en/5/developer_guides/debugging/error_handling/#logging-and-error-handling

unless the logger is set up to actually record that somewhere, nobody will ever see it.

Yup, that's true of all logging. Better to give the option than nothing though.

@kinglozzer
Copy link
Member Author

I’ve finally got around to this. Using LoggerInterface::class . '.errorhandler' results in the warning being output in the HTTP response, which breaks everything, so I’ve copied the approach from the old file migration task: https://github.com/silverstripe/silverstripe-assets/blob/1.13/_config/migration.yml. Essentially it’s a logger instance that doesn’t include an output handler so nothing appears in the HTTP output, but the warning is still logged to the error log

Copy link
Member

@GuySartorelli GuySartorelli left a 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.

@GuySartorelli GuySartorelli merged commit f4587b2 into silverstripe:4.3 May 23, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants