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

fix(GraphQL): fix interface conversion panic in v20.03 #5857

Merged
merged 2 commits into from
Jul 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 additions & 25 deletions graphql/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ import (
"time"

dgoapi "github.com/dgraph-io/dgo/v2/protos/api"
"github.com/dgraph-io/dgraph/gql"

"github.com/golang/glog"
"github.com/pkg/errors"

badgerpb "github.com/dgraph-io/badger/v2/pb"
"github.com/dgraph-io/badger/v2/y"
"github.com/dgraph-io/dgraph/graphql/dgraph"
"github.com/dgraph-io/dgraph/graphql/resolve"
"github.com/dgraph-io/dgraph/graphql/schema"
"github.com/dgraph-io/dgraph/graphql/web"
Expand Down Expand Up @@ -446,32 +444,28 @@ func newAdminResolverFactory() resolve.ResolverFactory {
return rf.WithSchemaIntrospection()
}

// graphQLSchemaNode represents the node which contains GraphQL schema
type graphQLSchemaNode struct {
Uid string `json:"uid"`
Schema string `json:"dgraph.graphql.schema"`
}

type gqlSchemaQryResp struct {
ExistingGQLSchema []graphQLSchemaNode `json:"ExistingGQLSchema"`
}

func upsertEmptyGQLSchema() (*gqlSchema, error) {
existingSchemaVar := "ExistingGQLSchema"
xidInSchemaVar := "XidInSchema"
gqlType := "dgraph.graphql"
/*
query {
ExistingGQLSchema as ExistingGQLSchema(func: type(dgraph.graphql)) {

qry := `query {
ExistingGQLSchema as ExistingGQLSchema(func: has(dgraph.graphql.schema)) {
uid
dgraph.graphql.schema
XidInSchema as dgraph.graphql.xid
}
}
*/
qry := &gql.GraphQuery{
Attr: existingSchemaVar,
Var: existingSchemaVar,
Func: &gql.Function{
Name: "type",
Args: []gql.Arg{{Value: gqlType}},
},
Children: []*gql.GraphQuery{
{Attr: "uid"},
{Attr: gqlSchemaPred},
{Attr: gqlSchemaXidKey, Var: xidInSchemaVar},
},
}
}`
/*
mutation @if(eq(len(ExistingGQLSchema),1) AND eq(len(XidInSchema),0)) {
set {
Expand Down Expand Up @@ -512,7 +506,7 @@ func upsertEmptyGQLSchema() (*gqlSchema, error) {
}

resp, err := resolve.NewAdminExecutor().Execute(context.Background(),
&dgoapi.Request{Query: dgraph.AsString(qry), Mutations: mutations, CommitNow: true})
&dgoapi.Request{Query: qry, Mutations: mutations, CommitNow: true})
if err != nil {
return nil, err
}
Expand All @@ -523,16 +517,16 @@ func upsertEmptyGQLSchema() (*gqlSchema, error) {
return &gqlSchema{ID: uid}, nil
}

result := make(map[string]interface{})
var result gqlSchemaQryResp
if err := json.Unmarshal(resp.GetJson(), &result); err != nil {
return nil, schema.GQLWrapf(err, "Couldn't unmarshal response from Dgraph mutation")
}

// the Alphas which didn't create the gql schema node, will get the uid here.
gqlSchemaNode := result[existingSchemaVar].([]interface{})[0].(map[string]interface{})
gqlSchemaNode := result.ExistingGQLSchema[0]
return &gqlSchema{
ID: gqlSchemaNode["uid"].(string),
Schema: gqlSchemaNode[gqlSchemaPred].(string),
ID: gqlSchemaNode.Uid,
Schema: gqlSchemaNode.Schema,
}, nil
}

Expand Down