Skip to content

Commit

Permalink
Modified code and test as per Michael review
Browse files Browse the repository at this point in the history
  • Loading branch information
JatinDev543 committed Jun 18, 2020
1 parent 7f6143d commit 907c156
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
9 changes: 9 additions & 0 deletions graphql/e2e/common/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,12 @@ func queryOnlyTypename(t *testing.T) {

expected := `{
"queryCountry": [
{
"__typename": "Country"
},
{
"__typename": "Country"
},
{
"__typename": "Country"
}
Expand Down Expand Up @@ -1175,6 +1181,9 @@ func queryNestedOnlyTypename(t *testing.T) {
{
"__typename": "Post"
},
{
"__typename": "Post"
}
]
}
]
Expand Down
10 changes: 5 additions & 5 deletions graphql/resolve/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package resolve
import (
"context"
"encoding/json"
"fmt"

"github.com/golang/glog"
otrace "go.opencensus.io/trace"

Expand Down Expand Up @@ -101,10 +101,10 @@ func (qr *queryResolver) rewriteAndExecute(ctx context.Context, query schema.Que
return emptyResult(schema.GQLWrapf(err, "Dgraph query failed"))
}

if string(resp.GetJson()) == fmt.Sprintf(`{"%s":[]}`, query.Name()) {
resp.Json = []byte(fmt.Sprintf(`{"%s":[{"dgraph.type":"%s"}]}`, query.Name(),
query.Type().Name()))
}
//if string(resp.GetJson()) == fmt.Sprintf(`{"%s":[]}`, query.Name()) {
// resp.Json = []byte(fmt.Sprintf(`{"%s":[{"dgraph.type":"%s"}]}`, query.Name(),
// query.Type().Name()))
// }

resolved := completeDgraphResult(ctx, query, resp.GetJson(), err)
resolved.Extensions =
Expand Down
16 changes: 15 additions & 1 deletion graphql/resolve/query_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ func intersection(a, b []uint64) []uint64 {
// there's only 7 posts, or if there's more that are missing 'text'.
// But, for GraphQL, we want to know about those missing values.
func addUID(dgQuery *gql.GraphQuery) {
if len(dgQuery.Children) == 0 {
uidChild := &gql.GraphQuery{
Attr: "uid",
Alias: "dgraph.uid",
}
dgQuery.Children = append(dgQuery.Children, uidChild)
} else {
addUID1(dgQuery)
}

}

func addUID1(dgQuery *gql.GraphQuery) {
if len(dgQuery.Children) == 0 {
return
}
Expand All @@ -181,7 +194,7 @@ func addUID(dgQuery *gql.GraphQuery) {
if c.Attr == "uid" {
hasUid = true
}
addUID(c)
addUID1(c)
}

// If uid was already requested by the user then we don't need to add it again.
Expand All @@ -193,6 +206,7 @@ func addUID(dgQuery *gql.GraphQuery) {
Alias: "dgraph.uid",
}
dgQuery.Children = append(dgQuery.Children, uidChild)

}

func rewriteAsQueryByIds(field schema.Field, uids []uint64, authRw *authRewriter) *gql.GraphQuery {
Expand Down

0 comments on commit 907c156

Please sign in to comment.