Skip to content

Problem getting pagination to work. #17

@deep-c

Description

@deep-c

Hey,

I am attempting to get pagination working using limit, offset, and order to no avail. I keep getting back the first 50 results and I am unsure if I am doing anything wrong.

I am attempting to do offset based pagination like so. Here is the message query.

const messageQuery = {
  messages: {
    type: new GraphQLList(messageType),
    args: {
      channelId: {
        type: GraphQLString
      },      
      order: {
        type: GraphQLString
      },
      limit: {
        type: GraphQLInt
      },
      offset: {
        type: GraphQLInt
      },      
    },
    resolve: resolve('Messages', null, {
      before: (opts, args, context, info) => {
        console.log('ARGS/OPTS', args, opts)
        console.log('offset', opts.offset, 'limit', opts.limit)
        return opts
      }
    })
  },
  message: {
    type: messageType,
    args: {
      id: {
        type: new GraphQLNonNull(GraphQLString)
      },
      order: {
        type: GraphQLString
      },
      ...commonArgs
    },
    resolve: resolve('Messages')
  }
};

The model is as follows:

const Messages = thinky.createModel("Messages", {
    id: type.string().uuid(4).allowNull(false),
    content: type.string().allowNull(false),
    channelId: type.string().allowNull(false),
    createdBy: type.string().uuid(4).allowNull(false),    
    createdOn: type.date().default(thinky.r.now()),    
})

Messages.relations = () => {
    Messages.belongsTo(thinky.models.Channels, "channel", "channelId", "id")
    Messages.belongsTo(thinky.models.Users, 'creator', 'createdBy', 'id')
}

The query is as such:

query MessagesForChannel($channelId: String!, $offset: Int, $limit: Int, $orderBy: String){
    messages(channelId: $channelId, offset: $offset, limit: $limit, order: $orderBy){
        id
        content
        createdOn
        creator {
            id
            displayName
            name {
                givenName
                familyName
                middleName
            }
            avatar
            status
        }
    }
}

I can see that the appropriate variables are being sent along with the query however the offset and limit args dont seem to be picked up and used when resolving the query.

variables
:
Object
channelId
:
"tech-links"
offset
:
350
orderBy
:
"reverse:createdOn"

I am using v0.4.0-rc-3 without relay. (Using apollo client and its offset based pagination http://dev.apollodata.com/react/pagination.html)

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions