Showing results for 
Search instead for 
Did you mean: 
Community Member

How can I use pagination at the root of a query in GraphQL?

I'm trying to figure out this new-fangled GraphQL API with hopes of speeding up a few of our slower REST API queries. I'd like to get a list of all courses for a given account (including sub-accounts), but I'm not sure how to create that query using pagination on the allCourses endpoint. I've tried this in GraphiQL:

query MyQuery {
   allCourses {

And I get the first 10 entries. But if I try:

query MyQuery {    
allCourses(start: 20) {...}

This gives me an error, saying "Unknown argument 'start'".

What am I missing? How do you do pagination for allCourses?

Thanks in advance for any help.

Labels (2)
Tags (1)
0 Kudos
1 Reply

 @chuck2 ,

This isn't a direct answer to your question about pagination, but perhaps it will help.

The graphql query you gave isn't paginated for me. It returns 55 courses. I think the name allCourses is confusing people and I was one of those until earlier this week. The allCourses returns information in the way that List your courses (GET /api/v1/courses) returns information for the current user. That request also returns 55 courses. In other words, allCourses is scoped to the user.

When you go to the schema on the right of the /graphiql and look for allCourses, you get "All courses viewable by the current user."

I wonder if you're getting 10 because you only have 10 and you're just thinking the results are paginated because that's what normally happens when you get 10 results? Perhaps you were expecting much more than 10 because you thought it would return all of the courses, not just all of your courses?

Anyway, there isn't any of the pagination controls with the allCourses like there are with the other items, further suggesting that it's not paginated. Pagination in GraphQL is explained on the GraphQL website. In Canvas, you will often see pagination in the connectors.

For example, if you expand the assignmentGroupConnection under allCourses, you will see that it supports parameters of afterbeforefirst, and last. It also has pageInfo that will give you the endCursor needed to pick up the next piece.