serlo / api.serlo.org

Public GraphQL API of https://serlo.org/
https://api.serlo.org/___graphql
Apache License 2.0
15 stars 4 forks source link

Threads sorted: newest first #142

Closed elbotho closed 3 years ago

elbotho commented 3 years ago

~Is it easy to sort the threads in the api? Or should we do the sorting in the frontend. Newest in top probably makes sense most of the time.~

kulla commented 3 years ago

Now, thats easy to change in the API.

kulla commented 3 years ago

How to implement it (for the workshop): The code at https://github.com/serlo/api.serlo.org/blob/master/src/graphql/schema/uuid/thread/utils.ts#L11-L25 needs to be changed. First you can have

const threads = await Promise.all(
          firstCommentIds.map((id) => toThreadPayload(dataSources.serlo, id))
        )

This variable can be sorted. It is of type ThreadData[], see https://github.com/serlo/api.serlo.org/blob/master/src/graphql/schema/uuid/thread/types.ts for type definitions

At https://github.com/serlo/api.serlo.org/blob/master/__tests__/schema/uuid/thread.ts the tests need to be updated as well.