You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the GraphQL spec, there’s no guarantee about the order that these will be interpreted, so the sort order might be interpreted as either Created ASC, Name ASC or Name ASC, Created ASC. It appears that webonyx/graphql-php will interpret them in the order they’re defined in the schema, not in the query or inputs.
We’ve managed to work around this by manually parsing the query in #563, but that only works if the sort order is baked into the query itself. When the sort order is passed as an argument to the query, the original order is lost as soon as the query is parsed (more info: #571 (comment)). That aside, manually inspecting the query AST to try to “fix” the sort order is probably an indication we’re approaching this the wrong way.
One alternative approach suggested is to use an array instead (a “list” in GraphQL speak). That might look something like:
[
{"created": "asc"},
{"name": "asc"}
]
If we could use that approach, I think it’d be important to preserve backward compatibility if at all possible. I haven’t looked at how that might be possible yet - perhaps interfaces or union types could help.
How to reproduce
Possible Solution
No response
Additional Context
No response
Validations
Check that there isn't already an issue that reports the same bug
Double check that your reproduction steps work in a fresh installation of silverstripe/installer (with any code examples you've provided)
The text was updated successfully, but these errors were encountered:
I’ve been trying to think how we might be able to set up types for this while preserving some kind of backward compatibility with the existing sort fields. The only way I can come up with is this:
typeQuery {
readMembers(
filter: MemberFilterFieldssort: MemberSortOptions
): [Member!]!
}
# New union type to support both old input (for bc) and new inputunionMemberSortOptions = MemberSortFields | MemberSortExpressions# Already existsenumSortDirection {
ASC DESC
}
# Already existsinputMemberSortFields {
created: SortDirectionname: SortDirection
}
# New enum of available fields to sort byenumMemberSortField {
name created
}
# New type# Necessary because it's not possible to do a union type like: MemberSortFields | [MemberSortExpression]typeMemberSortExpressions {
expressions: [MemberSortExpression!]!
}
# New typetypeMemberSortExpression {
field: MemberSortField,
direction: SortDirection
}
So args for a sorted query with the new sorting approach would look like:
What’s not clear to me, however, is if backward compatibility is really feasible. If people are doing introspection on the schema, and expecting e.g. the existing MemberSortFields input type to be returned, would switching that to a union type break things for them? How would we “deprecate” the old approach?
Module version(s) affected
v4, v5
Description
Currently sort arguments are passed as an object:
According to the GraphQL spec, there’s no guarantee about the order that these will be interpreted, so the sort order might be interpreted as either
Created ASC, Name ASC
orName ASC, Created ASC
. It appears thatwebonyx/graphql-php
will interpret them in the order they’re defined in the schema, not in the query or inputs.We’ve managed to work around this by manually parsing the query in #563, but that only works if the sort order is baked into the query itself. When the sort order is passed as an argument to the query, the original order is lost as soon as the query is parsed (more info: #571 (comment)). That aside, manually inspecting the query AST to try to “fix” the sort order is probably an indication we’re approaching this the wrong way.
One alternative approach suggested is to use an array instead (a “list” in GraphQL speak). That might look something like:
If we could use that approach, I think it’d be important to preserve backward compatibility if at all possible. I haven’t looked at how that might be possible yet - perhaps interfaces or union types could help.
How to reproduce
Possible Solution
No response
Additional Context
No response
Validations
silverstripe/installer
(with any code examples you've provided)The text was updated successfully, but these errors were encountered: