Question

I'm trying to figure out how to use Google Cloud Endpoints with paging. I am only getting back 10 results. I have set the property shouldFetchNextItems to YES. Also my query object does not have a nextToken or maxResults property. There is a GTLQueryCollectionProtocol with pageToken but I don't see where it is used.

static GTLServiceOwnit *service = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    service = [[GTLServiceOwnit alloc] init];
    service.retryEnabled = YES;
    service.shouldFetchNextPages = YES;
});

NSError *error;

NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];

GTLQueryOwnit *query = [GTLQueryOwnit queryForBrandList];

[service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, GTLOwnitBrandCollection *object, NSError *clouderror) {
   NSLog(@"counts: %d", [[object items] count]);
   ...

Edit: Here is my backend in python:

class Brand(EndpointsModel):
    name = ndb.StringProperty(required=True)

@Brand.query_method(path='brand',
                    http_method='GET',
                    name='brand.list')
def brand_list(self, query):
    """Exposes an API endpoint to query for brands for the current user"""
    return query.order(Brand.name)

Thanks,

Was it helpful?

Solution

Check out the paging sample from the documentation.

In order for the paging parameters to be included in your API, you'll need to explicitly include them in your method:

@Brand.query_method(query_fields=('limit', 'pageToken'),
                    path='brand',
                    http_method='GET',
                    name='brand.list')
def brand_list(self, query):
    """Exposes an API endpoint to query for brands for the current user"""
    return query.order(Brand.name)

The default value of the query limit is 10. You can change it but you should set a reasonable limit. It is the limit_default field in query_method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top