【问题标题】:Lighthouse GraphQL Sorting on relationLighthouse GraphQL 关系排序
【发布时间】:2022-07-12 03:53:57
【问题描述】:

我在另一个关系上遇到问题。我希望能够对前端关系中的列标题进行排序。这是我的设置:

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.$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'}],
          }
        },
      });

我收到错误 Expected type EntriesOrderByColumn at value[0].field。仅在作品中发布:[{field: 'PUBLISHED_AT', order: 'DESC'}] 我从错误和文档中的内容中得到了混合信号。帮忙?

【问题讨论】:

    标签: graphql laravel-lighthouse


    【解决方案1】:

    嗯...我在 GraphQL 方面不是最好的,但有同样的问题并找到了适合我的答案。

    尝试替换:

    $orderBy: [EntriesOrderByOrderByClause!]) {
    

    作者:

    $orderBy: [EntriesOrderByRelationOrderByClause!]) {
    

    【讨论】:

      猜你喜欢
      • 2020-08-11
      • 2020-05-01
      • 2019-11-23
      • 2020-04-20
      • 2020-10-03
      • 2020-05-12
      • 2020-06-01
      • 2019-12-02
      • 2020-04-18
      相关资源
      最近更新 更多