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

graphql: make updateGQLSchema always return the new schema #5540

Merged
merged 4 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
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
14 changes: 12 additions & 2 deletions graphql/admin/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -75,10 +79,12 @@ func (asr *updateSchemaResolver) Rewrite(
// Disable subscription.
schHandler.DisableSubscription()

_, 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
Expand Down Expand Up @@ -109,7 +115,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
}

Expand Down
5 changes: 5 additions & 0 deletions graphql/e2e/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,13 +740,18 @@ func addSchema(url, schema string) error {
}
}
}
Errors []interface{}
}

err = json.Unmarshal(resp, &addResult)
if err != nil {
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")
}
Expand Down