xorinzor
xorinzor

Reputation: 6477

Error when attempting to combine limit with paginate

When performing the GraphQL query below, lighthouse throws the following error:

Nuwave\Lighthouse\Pagination\PaginatorField::dataResolver(): Argument #1 ($root) must be of type Illuminate\Contracts\Pagination\LengthAwarePaginator, array given, called in /code/vendor/nuwave/lighthouse/src/Schema/Directives/FieldDirective.php on line 51

This only seems to happen when I combine limit and paginate. If I remove the limit: 1 from my query, or replace @paginate in my schema with @all, the request completes succesfully.

Why are these options seemingly incompatible?

Using lighthouse 5.48 and laravel 9.11

My query:

query getLastPlayed{
  requests(
    limit: 1
  ) {
    paginatorInfo{
      total
      hasMorePages
    }
    data {
      id
      media {
        title
        duration
      }
      requested_at
    }
  }
}

My schema:

type Request {
    id: ID!
    media: Media! @belongsTo
    requested_by: User @hasOne
    requested_at: DateTime!
    played_at: DateTime
}

type Query {
    requests(
            limit: Int @limit
        ): [Request!]! @paginate(defaultCount: 10)
}

Upvotes: 0

Views: 399

Answers (1)

thekonz
thekonz

Reputation: 56

don't use limit. the paginate directive already injects an argument called "first" into your query.

users(first: 10) will return only 10 users.

Upvotes: 2

Related Questions