-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Issues with sort fields #11368
Comments
cc @freiksenet |
Note that all of this is working as expected in the schema refactor branch - I noticed those issues when porting over the old tests, and noted them here so there is something public to refer to. |
Does this recent change have anything to do with it? #11381 |
@zslabs Could you specify what is broken for you? The sort examples in the graphql reference docs seem to work. |
Hey @stefanprobst,
|
@zslabs I'll look into it. |
@zslabs Ok, this needs more investigation. In a basic hello-world starter (with |
Unfortunately no; as it's a private repo. Here's a rundown of my
|
Just to clarify: broken sort means you get an Error, or it just doesn't sort (neither ASC nor DESC)? |
Sorry, my comment was pretty vague; no errors; just the query was not actually returning sorted results correctly (not respecting the params of the query). This was happening with both |
Hmm, at the moment, I'm out of ideas unfortunately -- this is working correctly for me with |
@stefanprobst I think I've found the issue. This isn't related to the core gatsby package, but Some of the dates are written as |
@DSchau Thank you very much for looking into this and appreciate that link as well! |
Here's a reproduction: The posts should be sorted in descending order (newest first) but clearly that's not the case. Upgrading to the latest |
@DSchau Thanks for the reproduction!
.map(field => v => {
const value = _.get(v, field)
return value instanceof Date ? value.toISOString() : value
}) EDIT: Yes that works |
But the more correct solution is that we should manually call resolvers for querying not only for |
Ok so I included both in #11656 because calling resolvers is the more general solution, but we might still need to stringify if at some point our GraphQLDate changes to Dates instead of strings. |
Hello! I'm running into a similar issue with sorting on fields added by setFieldsOnGraphQLNodeType. I'm not sure if my issue is the same as everyone else's here, but I've noticed that only fields of type GraphQLString are sortable when added by setFieldsOnGraphQLNodeType. I tried using the GraphQLDate from "gatsby/dist/schema/types/type-date", and while it completely works for querying, the field is not included in the sort enum. The same field shows up in the sort enum when the type is changed to GraphQLString. This is all on a custom type created in a plugin. I hope this info helps! |
to fix issues with sort fields ref. * gatsbyjs/gatsby#11368 * gatsbyjs/gatsby#11716
to fix issues with sort fields ref. * gatsbyjs/gatsby#11368 * gatsbyjs/gatsby#11716
@zslabs I guess you have already seen, the Date sorting issue should be fixed in @rogermparent Thanks for reporting! Your issue seems to be the third point in the initial issue description (sorting should work for scalar types like String, but not when we have to call field resolvers). On second thought, sorting Date fields added with |
@stefanprobst Thanks! Hadn't had a chance to confirm, but things do appear to be working correctly now - thanks! |
@stefanprobst I just threw together a minimal repo showcasing the problem, and in the process made a few discoveries.
Also, all my fields have resolvers that simply point to the real value (I'm doing it in my actual project as a janky, poor-man's nullable field for when no node has the value.) Find the repo here: https://github.com/rogermparent/gatsby-setfields-sort-example |
I just hit this
I don't see a Here are the relevant software versions.
Not sure if this is related or not, but it seemed like it! |
@rogermparent Thanks for the repo! It looks like there are actually two issues:
{
allSortableExampleNode(
filter: {
dateFieldDate: { ne: null }
stringFieldDate: { ne: null }
}
sort: {
fields: [dateFieldDate]
order: [DESC]
}
) {
edges {
node {
date
}
}
}
} This works because now the field resolvers for |
@marcysutton Did you add the |
@stefanprobst I missed that, it isn't in the plugin README! I made a note tonight to write a Gatsby RSS feed how-to since I haven't seen one...I'll be sure to include that detail. Thanks :) |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! Thanks for being a part of the Gatsby community! 💪💜 |
Some issues with sort fields:
___NODE
naming convention are included as is in the sort fields enum. This means (i) we cannot sort by fields on the linked node; (ii) we also cannot sort by the foreign-key value on the ___NODE field, because we replace triple underscores with dots. We have to do this because we unnecessarily store the underscored field names as enum values. (here and here)although we include fields added with theFixed; the same issue is probably true forsetFieldsOnGraphQLNodeType
API in the sort fields enum, we cannot sort on those fields, because we don't call field resolvers on sort fields before querying (only forfilter
fieldsdistinct
andgroup
field
arg)The text was updated successfully, but these errors were encountered: