dgraph icon indicating copy to clipboard operation
dgraph copied to clipboard

Support value variables for paging params (offset, after, first)

Open disconsented opened this issue 7 years ago • 8 comments

{

 var(func: eq(account, "100")){
   client{
       cid as uid  
   }
   msg as message_limit
 }
 messageCount(func: uid(cid)){
        count(messages)
   messages(orderdesc: timestamp, offset: val(msg)){
        uid
        payload
        timestamp
   }
 }
}

message_limit here is message_limit:int . . The essential point is that I want to be able to set values in the database to use as limits application side. The above results in : strconv.ParseInt: parsing "msg": invalid syntax which seems inconsistent considering that variables can be used for ordering as suggested by the documentation.

disconsented avatar Sep 04 '18 23:09 disconsented

Using val() with offset sounds like a valid feature.

Took another look at your specific use case. You’d like to do message limiting, so would it be better to use first: to retrieve only N messages? Instead of offset, which skips the first N messages and returns the rest.

danielmai avatar Oct 13 '18 03:10 danielmai

I think this feature could be very handy e.g:

{
#dummy query as empty query you can't use, other than aggregation.
  var(func: uid(0x1)){  
    amount as math(5)
    page   as math(2)
    OST as math(amount * page)
  }
  q(func: has(somePred), 
    orderasc: otherPred, first: val(amount), offset: val(OST) ) {
    expand(_all_)
  }
}

MichelDiz avatar May 02 '19 17:05 MichelDiz

I think I faced a similar problem working on my dgraph tech-demo. I'm trying to implement pagination and this is the query I assumed to work:

query PostsPage(
  $first: int = 4,
  $id: string = "ce9f834c2fd143e7a0994cd01564d990"
) {
  var(func: eq(Post.id, $id)) {
    p as uid
  }
  posts(
    func: has(Post.id),
    orderasc: Post.id,
    after: val(p),
    first: $first
  ) {
    uid
    Post.id
    Post.title
    Post.contents
  }
}

Unfortunately, it seems like I can't use p as an argument for after:

": strconv.ParseUint: parsing \"p\": invalid syntax"

I suddenly need 2 roundtrips to get the job done:

  • fetch the uid by id
  • then fetch the page using the uid

This is obviously bad because it could have been done with just a single simple query. Please correct me if I'm wrong.

romshark avatar May 23 '19 22:05 romshark

@romshark 's use case is the same as ours. It's a big issue that we can't do this... I am surprised this feature isn't already implemented...

paulrostorp avatar Jun 16 '20 15:06 paulrostorp

@paulrostorp romshark 's case is different. He is using DQL Variables (a concept imported from GraphQL). You can open another ticket for this, cuz this implementation is totally different. But please, first check if there isn't any other issue already on this topic.

Unless the case is a mix of both features. And the DQL Variables works fine on this case. I remember someone working on something related to GQL Vars a year ago, not sure.

Cheers.

MichelDiz avatar Jun 16 '20 16:06 MichelDiz

@MichelDiz You are right, our use case is not graphql, however it is similar to @romshark because we also use an identifier that is not the uid, therefore we'd need to be able to use val() in "after" in order to avoid doing two roundtrip queries. What I'm looking to do is something like this:

var(func: eq(someItem.xid, "someXid")) {
someItem as uid
}

items(func: ... , after: val(someItem)) {
...
}

paulrostorp avatar Jun 16 '20 16:06 paulrostorp

Okay, so this ticket is for your case too. I have asked @lgalatin to take a look at this ticket and manage what to do.

MichelDiz avatar Jun 16 '20 17:06 MichelDiz

This issue has been stale for 60 days and will be closed automatically in 7 days. Comment to keep it open.

github-actions[bot] avatar Aug 28 '24 02:08 github-actions[bot]