Skip to content

Commit

Permalink
fix(GraphQL): fix internal error when doing GraphQL schema introspect…
Browse files Browse the repository at this point in the history
…ion after drop all (#6268)

This PR fixes the "Internal error" response when querying the GraphQL schema after performing drop_all operation.

(cherry picked from commit d3bee33)
  • Loading branch information
minhaj-shakeel committed Sep 21, 2020
1 parent e1d747f commit 69b5aa4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
19 changes: 12 additions & 7 deletions graphql/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,13 +742,18 @@ func (as *adminServer) resetSchema(gqlSchema schema.Schema) {
// set status as updating schema
mainHealthStore.updatingSchema()

resolverFactory := resolverFactoryWithErrorMsg(errResolverNotFound)
// it is nil after drop_all
if gqlSchema != nil {
resolverFactory = resolverFactory.WithConventionResolvers(gqlSchema, as.fns)
}
if as.withIntrospection {
resolverFactory.WithSchemaIntrospection()
var resolverFactory resolve.ResolverFactory
// If schema is nil (which becomes after drop_all) then do not attach Resolver for
// introspection operations, and set GQL schema to empty.
if gqlSchema == nil {
resolverFactory = resolverFactoryWithErrorMsg(errNoGraphQLSchema)
gqlSchema, _ = schema.FromString("")
} else {
resolverFactory = resolverFactoryWithErrorMsg(errResolverNotFound).
WithConventionResolvers(gqlSchema, as.fns)
if as.withIntrospection {
resolverFactory.WithSchemaIntrospection()
}
}

// Increment the Epoch when you get a new schema. So, that subscription's local epoch
Expand Down
29 changes: 29 additions & 0 deletions graphql/e2e/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,35 @@ func TestConcurrentSchemaUpdates(t *testing.T) {
require.Equal(t, finalGraphQLSchema, resp.GqlSchema[0].Schema)
}

// TestIntrospectionQueryAfterDropAll make sure that Introspection query after drop_all doesn't give any internal error
func TestIntrospectionQueryAfterDropAll(t *testing.T) {
// First Do the drop_all operation
dg, err := testutil.DgraphClient(groupOnegRPC)
require.NoError(t, err)
testutil.DropAll(t, dg)
// wait for a bit
time.Sleep(time.Second)

introspectionQuery := `
query{
__schema{
types{
name
}
}
}`
introspect := &common.GraphQLParams{
Query: introspectionQuery,
}

// On doing Introspection Query Now, We should get the Expected Error Message, not the Internal Error.
introspectionResult := introspect.ExecuteAsPost(t, groupOneServer)
require.Len(t, introspectionResult.Errors, 1)
gotErrorMessage := introspectionResult.Errors[0].Message
expectedErrorMessage := "Not resolving __schema. There's no GraphQL schema in Dgraph. Use the /admin API to add a GraphQL schema"
require.Equal(t, expectedErrorMessage, gotErrorMessage)
}

// TestUpdateGQLSchemaAfterDropAll makes sure that updating the GraphQL schema after drop_all works
func TestUpdateGQLSchemaAfterDropAll(t *testing.T) {
updateGQLSchemaRequireNoErrors(t, `
Expand Down

0 comments on commit 69b5aa4

Please sign in to comment.