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 internal error when doing GraphQL schema introspection after drop all #6268

Merged
merged 5 commits into from
Aug 27, 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
19 changes: 12 additions & 7 deletions graphql/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,13 +768,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 @@ -279,6 +279,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