0

Suppose we have Series and Episodes, and each Series has many Episodes:

type Query {
  series: [Series!]! @paginate(defaultCount: 10)
  series(id: ID @eq): Series @find

  episodes: [Episode!]! @paginate(defaultCount: 10)
  episode(id: ID @eq): Episode @find
}

type Series {
  id: ID!
  title: String!
  episodes: [Episode]! @hasMany
  plot: String!
}

type Episode {
  id: ID!
  title: String!
  season: Int!
  series: Series! @belongsTo
  plot: String!
}

Everything works fine. We can query series and episodes and they are paginated.

The Lighthouse docs says we can also paginate relations by setting type on the @hasMany directive (https://lighthouse-php.com/master/api-reference/directives.html#hasmany) like so:

type Series {
  id: ID!
  title: String!
  episodes: [Episode]! @hasMany(type: "paginator")
  plot: String!
}

This works fine when querying series like this:

query series {
  series {
    paginatorInfo {
      total
      currentPage
      hasMorePages
    }
    data {
      title
      episodes {
        paginatorInfo {
          total
          currentPage
          hasMorePages
        }
        data {
          title
        }
      }
    }
  }
}

Series and their episodes each get paginated.

But now I can no longer query episodes directly:

query episodes {
  episodes {
    paginatorInfo {
      total
      currentPage
      hasMorePages
    }
    data {
      title
    }
  }
}

This returns the error No class 'EpisodePaginator' was found for directive 'paginate'" What does that mean exactly, and how do I get the ability to paginate both related models and all models directly?

clem
  • 123
  • 3
  • 10

2 Answers2

2

This was a bug and has been fixed in v4.8.1 https://github.com/nuwave/lighthouse/releases/tag/v4.8.1

clem
  • 123
  • 3
  • 10
1

Everything looks correct except for the fact that you have two queries with the same name:

type Query {
  series: [Series!]! @paginate(defaultCount: 10)
  series(id: ID @eq): Series @find
}

You will need to change one of those. I suspect what's happening is that you're overwriting the paginated query with one that only grabs a single series.

Try changing the name of the plural query to allSeries or something like that and see if that fixes your issue.

Jason Adams
  • 173
  • 1
  • 7
  • Thanks. I tried your suggestion but I still get the same error. I believe Lighthouse decides which query to use based the arguments provided, ie, `series {}` vs `series(id: 1) {}`, since I don't have issues querying either of them. Plus, I don't think the `series` query is even involved when querying `episodes` is it? – clem Jan 14 '20 at 16:44
  • @spawnia Okay. Still, that's not the source of the issue I'm having. I tried changing the first one to allSeries as suggested and still am getting the same error. – clem Jan 15 '20 at 16:38