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

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.

4 Replies
Community Manager
Message 2 of 5

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. 

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 5

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 5

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!

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

Solution
Copilot Lvl 3
Message 5 of 5

Re: GraphQL API Pagination

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