graphql-go-tools
graphql-go-tools copied to clipboard
In the schema.go file, we hope to optimize the error handling approach as shown below, in order to obtain error information in non-debug mode.
In the schema.go file, we hope to optimize the error handling approach as shown below, in order to obtain error information in non-debug mode. Here is an example of the optimized code:
func (c *ExecutableSchema) Make(ctx context.Context) (graphql.Schema, error) {
// ...
schema, err := graphql.NewSchema(*schemaConfig)
if err != nil {
if c.Debug {
j, _ := json.MarshalIndent(registry.dependencyMap, "", " ")
fmt.Println("Unresolved types, thunks will be used")
fmt.Println(string(j))
}
return schema, fmt.Errorf("failed to create schema: %w", err)
}
// create a new schema
return schema, nil
}