首页 > 解决方案 > GraphQL - Laravel - 默认为 OrderBy

问题描述

我正在为 laravel 运行灯塔,但默认情况下它不起作用@orderBy(没有传递参数)。

我按照那个指南,

https://lighthouse-php.com/master/api-reference/directives.html#orderby

预定义排序要为您的字段预定义默认顺序,请在字段上使用此指令:

type Query {   latestUsers: [User!]! @all @orderBy(column: "created_at", direction: DESC) } 

客户端不必向该字段传递任何参数,默认情况下仍会收到有序结果

并且不起作用,只需从 1 到 10 排序

{
  "data": {
    "latestUsers": [
      {
        "id": "1",
        "createdAt": "2021-06-22 18:35:13"
      },
      {
        "id": "2",
        "createdAt": "2021-06-22 18:35:13"
      },
      {
        "id": "3",
        "createdAt": "2021-06-22 18:35:13"
      },.....

我用:

Checking platform requirements for packages in the vendor dir
ext-ctype      7.4.19      success  
ext-date       7.4.19      success
ext-dom        20031129    success
ext-fileinfo   7.4.19      success
ext-filter     7.4.19      success
ext-gd         7.4.19      success
ext-hash       7.4.19      success
ext-iconv      7.4.19      success
ext-json       7.4.19      success
ext-libxml     7.4.19      success
ext-mbstring   7.4.19      success
ext-openssl    7.4.19      success
ext-pcre       7.4.19      success
ext-phar       7.4.19      success
ext-simplexml  7.4.19      success
ext-spl        7.4.19      success
ext-tokenizer  7.4.19      success
ext-xml        7.4.19      success
ext-xmlreader  7.4.19      success
ext-xmlwriter  7.4.19      success
ext-zip        1.15.6      success
ext-zlib       7.4.19      success
lib-pcre       10.35       success
php            7.4.19      success

标签: laravelgraphqllaravel-lighthouse

解决方案


您必须确保至少在Lighthouse v5.1.0上运行。


推荐阅读