Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 6

GraphQL API Pagination

Solved! Go to Solution.

I have a GraphQL query to search repositories and I want to paginate my result.

 

search(first: $first, after:$cursor, query: $query, type: $type) {
    edges {
        node {
            ... on Repository {
                name
                description
                forkCount
                owner {
                    avatarUrl
                }
            }
        }
    }
    pageInfo {
        hasNextPage
        endCursor
    }
}

 

The query works fine when provided with a cursor. When I want to get only the first page and provide the query with a null cursor to get the first page, I get "Variable cursor of type String! was provided invalid value" error.

How can I retrieve the first page without having to write another query with no cursor parameter?

 

Any help would be appreciated.

5 Replies
Community Manager
Message 2 of 6

Re: GraphQL API Pagination

Hi @tartarJR,

 

Thanks for being here! If I'm not mistaken you'd have to send the initial request again because no variables are specified :( Let me do a little digging on my end and see if there are any alternatives. 


Best,
AndreaG

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

Copilot Lvl 2
Message 3 of 6

Re: GraphQL API Pagination

Hi Andrea 

 

Thank you for your help. Please let me know if you can find any alternatives.

Community Manager
Message 4 of 6

Re: GraphQL API Pagination

Hey @tartarJR,

 

Thanks for your patience, looks like the query works fine on our end take a look:

56269290-a4d12480-60f3-11e9-8725-606fbdf494ab.png

 

Would you please attempt you query again making sure to define the $after cursor parameter as $after: String. Please let me know if this does the trick, I hope this helps!


Best,
AndreaG

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

Copilot Lvl 2
Message 5 of 6

Re: GraphQL API Pagination

Hey @AndreaGriffiths11 

I was working on the search option to list all the available repositories using github api. The search option has an first field and has a limit of 100, iam trying to fetch 500 repositories, is there an alternative to do that ?

 

Code:

 

query {
rateLimit{
cost
remaining
resetAt
}
search( query: "-js created:>2015-01-01 language:JavaScript", type:REPOSITORY ,first: 500) {
repositoryCount
pageInfo {
hasNextPage
endCursor
startCursor
}
edges {
node {
... on Repository {
name
url
}
}
}
}

}

 

"message": "Requesting 500 records on the `search` connection exceeds the `first` limit of 100 records.",
"type": "EXCESSIVE_PAGINATION",

 

Thank you

Solution
Copilot Lvl 3
Message 6 of 6

Re: GraphQL API Pagination

Just remove the `!` from String to make the variable accept either a String or a null value.