0

I'm having issues on another relation. I want the ability to sort on the column title that is in the relation on the front end. Here's my setup:

extend type Query {
  entries(first: Int!, 
    page: Int, 
    type: String @eq, 
    site_id: ID @eq,
    orderBy: _ @orderBy(
        columns: ["created_at", "published_at"],
        relations: [{ relation: "content", columns: ["title"] }]
      )
   ): [Entry!]! @paginate
}


export const ALL_SITE_ENTRIES = gql`
  query Entries(
    $first: Int!, 
    $page: Int, 
    $type: String, 
    $site_id: ID, 
    $title: Mixed = null,
    $orderBy: [EntriesOrderByOrderByClause!]) {
    entries(
        first: $first, 
        page: $page, 
        type: $type, 
        site_id: $site_id, 
        hasContent: {column: TITLE, operator: LIKE, value: $title},
        orderBy: $orderBy
      ) {
      data {
        ...EntryDetails
        content{
          id
          title
          status
        }
      }
      paginatorInfo {
        currentPage
        lastPage
        total
      }
    }
  }
  ${EntryDetailsFragment}
`

Now according to the documentation on sorting, this should be fine. Published at and created at work just fine and dandy. When I try to sort on title, by

My Apollo call:

this.$apollo.addSmartQuery('entries', {
        query: ALL_SITE_ENTRIES,
        fetchPolicy: 'no-cache',
        variables() {
          return {
            type: this.entryType,
            site_id: null,
            blog_type: this.siteSettings.blog_type,
            first: 25,
            page: this.selectedPage,
            orderBy: [{content: {column: 'TITLE'}, order: 'DESC'}],
          }
        },
      });

I get the error Expected type EntriesOrderByColumn at value[0].field. Published at works with just: [{field: 'PUBLISHED_AT', order: 'DESC'}] I'm getting mixed signals from the errors and what the documentation says. Help?

cbloss793
  • 1,555
  • 4
  • 19
  • 30

2 Answers2

0

Well... I'm not the best on GraphQL, but had the same question and found the answer that worked for me.

Try replacing:

$orderBy: [EntriesOrderByOrderByClause!]) {

by:

$orderBy: [EntriesOrderByRelationOrderByClause!]) {
Daniel
  • 1
0

Sorry I bother here, buy I have a question related.

I have Products that have One Category but I cant SortBy Category. How can I do that?

My Query

query getProducts($orderBy: [QueryGetProductsOrderByRelationOrderByClause!]) {
  getProducts(orderBy: $orderBy) {
   id
   code
   article
   category{
     id
     name
   }
   stock
   stockMin
   priceBuy
   priceSell
 }
}

My parameters

{
  "orderBy": {
    "column": {"category": {
      "column": "NAME"
    },
    "order": "DESC"
    }
  }
}

The structure

getProducts(
        orderBy: _
            @orderBy(relations: [{ relation: "category", columns: ["name"] }])
    ): [Product!]!
    

type Product {
    id: ID
    code: String
    article: String

    category: Category
}
type Category {
    id: ID
    name: String
    products: [Product]
}
Agustin
  • 215
  • 1
  • 2
  • 14