graphql-go-tools icon indicating copy to clipboard operation
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.

Open vyks520 opened this issue 2 years ago • 0 comments

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
}

vyks520 avatar Aug 29 '23 11:08 vyks520