Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with cursor based pagination #140

Closed
sylwiaeb opened this issue Mar 2, 2016 · 4 comments
Closed

Issue with cursor based pagination #140

sylwiaeb opened this issue Mar 2, 2016 · 4 comments

Comments

@sylwiaeb
Copy link

sylwiaeb commented Mar 2, 2016

Hi all,

I'm using ember 2.3.0 with ember-data and JSONApi and trying to get this working with Facebook Graph api cursor pagination. My response looks like this:

{
next: "/api/posts?after=NDI5NjEzODQ3MjIxNDc2"
prev: "/api/posts?before=OTA4Mzk3Njg1OTQzNjg1"
}

And I stuck at this point:

  • this.set('_minId', posts.get('lastObject.id')); is undefined but this.set('_minId', posts.get('lastObject').get('id'); seems to be working not sure why
  • this.set('_minUpdatedAt', posts.get('lastObject.updated_at').toISOString()); also is undefined but that's because my model doesn't have updated_at ? so my question is should I set this prop when loading model or something?
@davidgoli
Copy link
Collaborator

It would be nice (ideal, even) if this addon supported JSONAPI links-based pagination such as you have here. In fact you don't really need ember-infinity to build your request at all, and since you're hitting the FB Graph API I'm guessing you're not using Ember Data either? It seems the difficulty here lies in getting Ember Data to use those links for pagination instead of building it via store.query and your Adapter.

The docs refer to _minId and _minUpdatedAt just as an example; in practice it's up to you to pull out whatever ids or properties are used by your API from your response. Here, it looks like you'll want NDI5NjEzODQ3MjIxNDc2 and NDI5NjEzODQ3MjIxNDc2. But as I said above, you probably don't want to be going through the store at all since those links are already built for you. In this case, you may not want or need the Ember Infinity Route mixin at all.

@sylwiaeb
Copy link
Author

sylwiaeb commented Mar 3, 2016

@davidgoli I'm using Ember Data (for the first time..). So you say I don't need this mixin at all but then how do I make a request for next link?

@davidgoli
Copy link
Collaborator

@sylwiaeb well, Ember Data is... opinionated about how requests are built. Before diving in with Ember Infinity I'd suggest building a couple routes that don't use Ember Infinity just to get a feel for how Ember Data works with your backend. In brief, Ember Data builds your urls for you, using an adapter. Take a look at these guides for more info:

http://emberjs.com/api/data/classes/DS.Store.html#method_query
http://emberigniter.com/fit-any-backend-into-ember-custom-adapters-serializers/

@sylwiaeb
Copy link
Author

sylwiaeb commented Mar 3, 2016

Thanks for tips and pointing me into right direction. Closing now, will update if this work.

@sylwiaeb sylwiaeb closed this as completed Mar 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants