graphqlpagination

Unknown argument \"hasNextPage\" on field \"pageInfo\" GraphQL


How to implement pagination for graphQL Query? I keep receiving:

"message": "Unknown argument "hasNextPage" on field "pageInfo" of type "Core_EventPeopleConnection"."

query myquery($viewId: ID!,$hasNextPage: Boolean!, $endCursor: String!){
  Core_eventPeopleListView(viewId: $viewId){
    id
    people{
      pageInfo(hasNextPage: true,endCursor: $endCursor){
        hasNextPage
        endCursor
      }
     nodes{
      firstName
      lastName
      jobTitle
      organization
      websiteUrl
    } 
    }
    }    
    }
Variables:
        {
      "viewId":"RXZlbnRWaWV3XzMyMTY1Mw==",
      "endCursor": "WyJhZ2Fyd2FsIiwic2hydXRpIiwiUlhabGJuUlFaVzl3YkdWZk1UVXhPREkzTlRVPSJd",
      "hasNextPage": true
    }

Solution

  • In Relay specification, hasNextPage is not an argument, but a field that is returned from the API to tell you if you can paginate further. Just remove the argument:

    query myquery($viewId: ID!,$hasNextPage: Boolean!, $endCursor: String!){
      Core_eventPeopleListView(viewId: $viewId){
        id
        people{
          pageInfo(endCursor: $endCursor){
            hasNextPage
            endCursor
          }
          nodes{
            firstName
            lastName
            jobTitle
            organization
            websiteUrl
          } 
        }
      }    
    }