Fetching paginated posts
In the post service, we'll define and implement a getPostsByUserId()
method that will be called by the profile component to retrieve paginated posts belonging to a certain user. As an assignment, we'll also implement a getFeed()
method to retrieve the network's most recent posts, regardless of who posted them. Proceed as follows:
- Open the
core/services/post/post.service.ts
file and add the following imports to it:import { Apollo } from 'apollo-angular'; import { GetPostsByUserIdDocument, GetPostsByUserIdQuery, GetPostsByUserIdQueryVariables } from '@ngsocial/graphql/documents';
These imports were generated by the GraphQL code generator.
- Inject the
Apollo
service, as follows:constructor( /* ... */ private apollo: Apollo) { }
- Define a
getPostsByUserId()
method, as follows:getPostsByUserId( userId: string, offset?: number...