Skip to content
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

feat(Query): Enable persistent queries in dgraph #6788

Merged
merged 10 commits into from
Oct 27, 2020

Conversation

all-seeing-code
Copy link
Contributor

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

Motivation

Enable persistent queries as discussed in RFC on discuss.

This PR fixes: GRAPHQL-721

This feature works out-of-the-box with Apollo client for GraphQL

Components affected by this PR

Query package

Does this PR break backwards compatibility?

No

Testing

Added following tests in:

  • persistedQuery in common.go. It is an end-to-end test which checks following cases:

    1. If incorrect sha is given throw with provided sha doesn't match the query
    2. If only sha is given and it is not present in dgraph throw with PersistedQueryNotFound
    3. If both query and sha are given and they match, then execute query and persis the query-sha pair. Check for no error.
    4. Use sha provided in step iii to execute the query and check that it throws no error.
    5. Do step iv via a GET request

Fixes

Fixes GRAPHQL-721


This change is Reviewable

@github-actions github-actions bot added area/graphql Issues related to GraphQL support on Dgraph. area/schema Issues related to the schema language and capabilities. labels Oct 22, 2020
x/keys.go Show resolved Hide resolved
schema/schema.go Outdated Show resolved Hide resolved
edgraph/graphql.go Outdated Show resolved Hide resolved
if len(query) == 0 {
return errors.New("PersistedQueryNotFound")
}
if !hashMatches(query, sha256Hash) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we do this at the top of the function? Either way

@@ -32,10 +32,18 @@ type Request struct {
Query string `json:"query"`
OperationName string `json:"operationName"`
Variables map[string]interface{} `json:"variables"`
Extensions struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Leave a comment here, that we should add explicit types for all extensions that we support in dgraph

@@ -253,6 +259,13 @@ func getRequest(ctx context.Context, r *http.Request) (*schema.Request, error) {
query := r.URL.Query()
gqlReq.Query = query.Get("query")
gqlReq.OperationName = query.Get("operationName")
if extensions, ok := query["extensions"]; ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

check length(extensions) before json decoding

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.

Reviewable status: 0 of 6 files reviewed, 8 unresolved discussions (waiting on @anurags92, @gja, @manishrjain, @MichaelJCompton, @pawanrawal, and @vvbalaji-dgraph)


graphql/admin/admin.go, line 291 at r1 (raw file):

		getAllowedCORSOrigins: Cors
		querySchemaHistory(first: Int, offset: Int): [SchemaHistory]
		queryPersistedQuery: PersistedQuery

I am not sure, but should this query have IP whitelisting and Guardian only access (if ACL is enabled)?


graphql/schema/request.go, line 35 at r1 (raw file):

Previously, gja (Tejas Dinkar) wrote…

Leave a comment here, that we should add explicit types for all extensions that we support in dgraph

This is the first extension that comes in GraphQL request, we already have explicit types for the ones which go in GraphQL response.
But, what we should do is mark this a separate type called RequestExtensions instead of saying struct { ... }


graphql/web/http.go, line 219 at r1 (raw file):

Quoted 9 lines of code…
	if err != nil {
		write(w, schema.ErrorResponse(err), strings.Contains(r.Header.Get("Accept-Encoding"), "gzip"))
		return
	}
	if err = edgraph.ProcessPersistedQuery(ctx, gqlReq); err != nil {
		write(w, schema.ErrorResponse(err), strings.Contains(r.Header.Get("Accept-Encoding"), "gzip"))
		return
	}
	res = gh.resolver.Resolve(ctx, gqlReq)

I believe we should just extended the if else logic instead of doing multiple returns and code duplication.


schema/schema.go, line 695 at r1 (raw file):

Previously, gja (Tejas Dinkar) wrote…

no need for index here

+1


x/keys.go, line 564 at r1 (raw file):

Previously, gja (Tejas Dinkar) wrote…

this may be too much, check with pawan

I think, this one should be there. There are various checks which happen for these pre-defined things at a lot of places.

@all-seeing-code all-seeing-code merged commit 3b44d3f into master Oct 27, 2020
@all-seeing-code all-seeing-code deleted the anurags92/PersistedQuery branch October 27, 2020 13:16
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. area/schema Issues related to the schema language and capabilities.
Development

Successfully merging this pull request may close these issues.

3 participants