Cached results in DQL possible? @cacheControl

query @cacheControl(maxAge: 15){
  queryReview(filter: { comment: {alloftext: "Fantastic"}}) {
    comment
    by {
      username
    }
    about {
      name
    }
  }
}

https://dgraph.io/docs/graphql/queries/cached-results/#

Hi we have that awesome feature in graphql. But what about DQL? Can I use that feature in DQL too?

Because it is quite important. E.g I want to do this (because this is not currently supported in GraphQL)

query {  
   post1 as var(func:type(Author)) @cascade {
      Author.posts : Author.posts @filter(eq(Post.title, "Dgraph")){
         uid
      }
   }

   queryAuthor(func: type(Author)) @filter(eq(Author.name,"Alice") or uid(post1)){
        Author.name : Author.name
        Author.posts  : Author.posts {
        Post.title : Post.title
        Post.text : Post.text 
          dgraph.uid : uid
        }
        dgraph.uid : uid
      }
    }

So, many users might search for Posts with Dgraph as the title. But only a few people might search for Posts with Alice as the Author. What I want to do to save resources:

query  @cacheControl(maxAge: 15) {  
   post1 as var(func:type(Author)) @cascade {
      Author.posts : Author.posts @filter(eq(Post.title, "Dgraph")){
         uid
      }
   }

   queryAuthor(func: type(Author)) @filter(eq(Author.name,"Alice") or uid(post1)){
        Author.name : Author.name
        Author.posts  : Author.posts {
        Post.title : Post.title
        Post.text : Post.text 
          dgraph.uid : uid
        }
        dgraph.uid : uid
      }
    }

Is this possible? If No, are the smartest roundabouts to achieve that? I could do the first query from my server client with graphql, and then do the second DQL client, but then I would have big increased latency because client -> dgraph -> client -> dgraph -> client and I want to achieve client -> dgraph -> client

I cache the HTTP response for each query on my server. This way you can be very flexible. Also, Dgraphs GraphQL caching, which you mentioned, is only on the browser/CDN level.

Btw, your queries look a bit inefficient. Instead of getting all nodes of a certain type and then filtering for a title or name you should immediately filter for the title or name and after that check the type. You might not even need the type check, if the predicate only exists in one type.

1 Like

Thank you very much!!! Then I will use dgraph cache header with Cloudflare Workers Cache API, thanks!!

the example was just copy pasted from here RFC: Nested Filters in GraphQL (y)