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

Order by related fields #95

Open
marktani opened this Issue Feb 9, 2017 · 32 comments

Comments

Projects
@marktani
Copy link
Contributor

commented Feb 9, 2017

Example: a User has many Posts. Should be possible to order the Posts by User name.

Maybe:

query {
  allPosts(orderByRelated: [user_name_ASC]) {
    id
  }
}
@cameronk

This comment has been minimized.

Copy link

commented Jun 16, 2017

This would be a lifesaver!

@edtsech

This comment has been minimized.

Copy link

commented Jul 12, 2017

@marktani any workaround we can use for the time being?

@marktani

This comment has been minimized.

Copy link
Contributor Author

commented Jul 13, 2017

The best workaround I'm aware of, is to order items client side 🙂

@shanecav

This comment has been minimized.

Copy link

commented Aug 5, 2017

It would be great to be able to order by "to-many" related fields as well (by the count of related items).

For example, to get a list of the top 10 most voted-for links (assuming votes is a related field of type [Vote!]!):

query {
  allLinks(first: 10, orderBy: votes_DESC) {
    id
    url
    description
    _votesMeta {
      count
    }
  }
}

Currently, to get that list you'd have to query for every Link and then sort/slice it on the client, which is potentially a ton of overfetching.

@kenyk7

This comment has been minimized.

Copy link

commented Oct 20, 2017

A question for when they plan to add this improvement?

@studentIvan

This comment has been minimized.

Copy link

commented Oct 21, 2017

+1 for this

@jeromeky

This comment has been minimized.

Copy link

commented Nov 5, 2017

+1

1 similar comment
@danstepanov

This comment has been minimized.

Copy link

commented Nov 12, 2017

+1

@serverlesspolska

This comment has been minimized.

Copy link

commented Nov 27, 2017

I see a lot of 👍
Dear GraphCool when do you plan to implement that?

@martinsura

This comment has been minimized.

Copy link

commented Dec 19, 2017

Must-have feature!

@schickling schickling added this to the 1.1 milestone Jan 6, 2018

@marktani marktani removed this from the 1.1 milestone Jan 22, 2018

@danielrasmuson

This comment has been minimized.

Copy link

commented Feb 24, 2018

In my case this table will have thousands of rows. My users won't be able to sort the table by "createdBy" or "dataset" until this feature lands.

screen shot 2018-02-24 at 11 47 25 am

@studentIvan

This comment has been minimized.

Copy link

commented Feb 25, 2018

@danielrasmuson you can create some sortable index just as temporary solution :)

@PascalSenn

This comment has been minimized.

Copy link

commented Apr 18, 2018

Have a look at #62
This would solve the issues:

query{
  servers(
  orderBy: {
    active: DESC
    assetNumber: ASC
    customer: {
        name:ASC 
   }
  }
  ) {
    id
    active
    assetNumber
    customer {
         name
    }
  }
}
@harrisrobin

This comment has been minimized.

Copy link

commented Aug 27, 2018

+1

@iyeremuk

This comment has been minimized.

Copy link

commented Oct 25, 2018

+1

@mcmar

This comment has been minimized.

Copy link

commented Nov 7, 2018

Echoing what @PascalSenn said, but updating orderBy to take an array. Arrays have implicit positioning. Objects aren't guaranteed that.
Additionally, every related ordering statement must also take an array, so that we can use multiple sort statements on a related field. (ie customer)

query {
  servers(
    orderBy: [{
      active: DESC
    }, {
      assetNumber: ASC
    }, {
      customer: [{
        name: ASC 
      }]
    }]
  ) {
    id
    active
    assetNumber
    customer {
      name
    }
  }
}

This proposal also has nice nesting where the input type for CustomerOrderByInput nests inside ServersOrderByInput. That prevents the infinitely expanding types that you would see for customer_name_ASC or customer_paymentInfo_expiryDate_ASC or customer_paymentInfo_issuer_headquarters_region_population_ASC.

The only problem I still have with this proposal is that each object must only have 1 key-value pair, but there's no way in my mind to enforce that. If anyone else has a proposal that would address this concern, please let me know.

@sorenbs

This comment has been minimized.

Copy link
Member

commented Nov 14, 2018

This continues to be an important feature for us. I'll update this issue when we have a concrete timeframe. See also this explanation for why we were unable to ship this feature in Q3 as planned.

@mcmar - I like how your proposal is more powerful than the originally proposed syntax. At the same time I am concerned about the added syntactic complexity compared to the original proposal.
Another consideration is that this syntax would require a breaking change, which might not be worth it for this extra expressiveness.

@mcmar

This comment has been minimized.

Copy link

commented Nov 15, 2018

@sorenbs If you're switching orderBy from FooOrderByInput to [FooOrderByInput!], wouldn't that be a breaking change anyway? I've noticed there's some magic in my generator that turns create: [FooCreateWithoutBarInput!] into create?: FooCreateWithoutBarInput[] | FooCreateWithoutBarInput and allows me to actually query with a single FooCreateWithoutBarInput even though the schema says otherwise. Maybe you can pull some similar wizardry here?

Haha. Just noticed that you commented on this very issue in the graphql repo 2.5 years ago:
graphql/graphql-js#207 (comment)

And more recent ones: graphql/graphql-spec#488 (comment)

I think an inputUnion type would eventually solve all these problems and allow us to have our cake and eat it too with regards to backwards compatibility. Sadly, that seems to be a long way away.

@sorenbs

This comment has been minimized.

Copy link
Member

commented Nov 17, 2018

@mcmar - see the Input Coercion section in the spec. It's specified behaviour, and quite useful for cases like this :-)

@stale

This comment has been minimized.

Copy link

commented Jan 8, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status/stale label Jan 8, 2019

@stale stale bot closed this Jan 18, 2019

@valentinbe

This comment has been minimized.

Copy link

commented Jan 23, 2019

+1 for this

@m3hari

This comment has been minimized.

Copy link

commented Jan 29, 2019

+1 What is the latest workaround

@pantharshit00 pantharshit00 reopened this Jan 29, 2019

@vhuang88

This comment has been minimized.

Copy link

commented Jan 30, 2019

+1

@cormarti

This comment has been minimized.

Copy link

commented Jan 31, 2019

Very interesting feature actually... I think a lot of prisma's users would like this implementation !!

Also looking for a workaround if someone has another solution than client side ordering :)

@dimjohn

This comment has been minimized.

Copy link

commented Feb 1, 2019

+1

@stale stale bot removed the status/stale label Feb 1, 2019

@chrisbotmind

This comment has been minimized.

Copy link

commented Feb 1, 2019

+1 we need this

@craigcbrunner

This comment has been minimized.

Copy link

commented Feb 5, 2019

Please add this and order by multiple fields!

@darthmolly

This comment has been minimized.

Copy link

commented Mar 14, 2019

+1

@nk1tz

This comment has been minimized.

Copy link

commented Mar 23, 2019

+1
I have a need for exactly this.
:)

@tandriamanga

This comment has been minimized.

Copy link

commented Mar 26, 2019

+1 💯

@terion-name

This comment has been minimized.

Copy link

commented Apr 1, 2019

VERY needed

@KumarAbhirup

This comment has been minimized.

Copy link

commented Apr 12, 2019

is it yet not built???? how do I order my posts by number of upvotes???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.