Skip to content

feat(Query): Add cacheControl directive that adds headers in the response #6799

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

Merged
merged 6 commits into from
Oct 27, 2020

Conversation

all-seeing-code
Copy link
Contributor

@all-seeing-code all-seeing-code commented Oct 26, 2020

Motivation

This PR adds support for users to enable browser/CDN side caching for their queries. Users can specify @cacheControl(maxAge: 15) at the top of their query. This would result in the response being returned with appropriate HTTP headers so that browsers and CDNs can cache the response.
More details can be read on discuss.

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

http headers returned:

Cache-Control: public,max-age=15
Vary: Accept-Encoding

This PR fixes: GRAPHQL-722

Components affected by this PR

  1. Directives
  2. Http responses

Does this PR break backwards compatibility?

No

Testing

Added following tests in:

[WIP]

Fixes

Fixes GRAPHQL-722


This change is Reviewable

@github-actions github-actions bot added the area/graphql Issues related to GraphQL support on Dgraph. label Oct 26, 2020
@@ -343,6 +344,13 @@ func (o *operation) Mutations() (ms []Mutation) {
return
}

func (o *operation) CacheControl() string {
if o.op.Directives.ForName(cacheControlDirective) == nil {
return ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private,no-cache would work instead of empty string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding header only if the directive is there, otherwise no header.

@all-seeing-code all-seeing-code changed the title feat(query): Add cacheControl directive that adds headers in the response feat(Query): Add cacheControl directive that adds headers in the response Oct 27, 2020
Copy link
Contributor

@abhimanyusinghgaur abhimanyusinghgaur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 3 of 5 files at r1, 1 of 2 files at r2, 3 of 46 files at r3.
Reviewable status: 7 of 52 files reviewed, 3 unresolved discussions (waiting on @abhimanyusinghgaur, @anurags92, @gja, @MichaelJCompton, and @pawanrawal)

@all-seeing-code all-seeing-code merged commit 13191fd into master Oct 27, 2020
@all-seeing-code all-seeing-code deleted the anurags92/cache-control branch October 27, 2020 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/graphql Issues related to GraphQL support on Dgraph.
Development

Successfully merging this pull request may close these issues.

3 participants