diff --git a/graphql/admin/schema.go b/graphql/admin/schema.go index be7fcb3abac..8c0506f39ed 100644 --- a/graphql/admin/schema.go +++ b/graphql/admin/schema.go @@ -38,6 +38,10 @@ type updateSchemaResolver struct { mutation schema.Mutation + // new GraphQL schema that is given as mutation input + newSchema string + // GraphQL schema that is generated from that input + generatedSchema string // dgraph schema that is generated from the mutation input newDgraphSchema string @@ -73,11 +77,12 @@ func (asr *updateSchemaResolver) Rewrite( return nil, err } - _, err = schema.FromString(schHandler.GQLSchema()) + asr.generatedSchema = schHandler.GQLSchema() + _, err = schema.FromString(asr.generatedSchema) if err != nil { return nil, err } - + asr.newSchema = input.Set.Schema asr.newDgraphSchema = schHandler.DGSchema() // There will always be a graphql schema node present in Dgraph cluster. So, we just need to @@ -108,7 +113,11 @@ func (asr *updateSchemaResolver) Execute( if req == nil || (req.Query == "" && len(req.Mutations) == 0) { // For schema updates, Execute will get called twice. Once for the // mutation and once for the following query. This is the query case. - b, err := doQuery(asr.admin.schema, asr.mutation.QueryField()) + b, err := doQuery(&gqlSchema{ + ID: asr.admin.schema.ID, + Schema: asr.newSchema, + GeneratedSchema: asr.generatedSchema, + }, asr.mutation.QueryField()) return &dgoapi.Response{Json: b}, err } @@ -118,7 +127,8 @@ func (asr *updateSchemaResolver) Execute( return nil, err } - _, err = (&edgraph.Server{}).Alter(ctx, &dgoapi.Operation{Schema: asr.newDgraphSchema}) + _, err = (&edgraph.Server{}).Alter(ctx, &dgoapi.Operation{Schema: asr.newDgraphSchema, + RunInBackground: false}) if err != nil { return nil, schema.GQLWrapf(err, "succeeded in saving GraphQL schema but failed to alter Dgraph schema ") diff --git a/graphql/e2e/common/common.go b/graphql/e2e/common/common.go index b5b62a9004c..afb86319f2b 100644 --- a/graphql/e2e/common/common.go +++ b/graphql/e2e/common/common.go @@ -705,6 +705,7 @@ func addSchema(url string, schema string) error { } } } + Errors []interface{} } err = json.Unmarshal(resp, &addResult) @@ -712,6 +713,10 @@ func addSchema(url string, schema string) error { return errors.Wrap(err, "error trying to unmarshal GraphQL mutation result") } + if len(addResult.Errors) > 0 { + return errors.Errorf("%v", addResult.Errors) + } + if addResult.Data.UpdateGQLSchema.GQLSchema.Schema == "" { return errors.New("GraphQL schema mutation failed") }