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

Added Support for CustomErrorFormatter #46

Closed
wants to merge 2 commits into from

Conversation

racerxdl
Copy link
Contributor

@racerxdl racerxdl commented Aug 11, 2018

This is an add-on for graphql-go/graphql#379 (it requires that to be merged to compile)

It basically adds a feature to be able to set a custom error formatter in case you have custom error objects returning in queries / mutation fields.

Example:

func CustomFormat(err error) gqlerrors.FormattedError {
	switch err := err.(type) {
	case *gqlerrors.Error:
		cf := CustomFormat(err.OriginalError)
		cf.Locations = err.Locations
		cf.Path = err.Path
		return cf
	case gqlerrors.ExtendedError:
		return gqlerrors.FormatError(err)
	case *QuantoError.ErrorObject:
		return err.ToFormattedError()
	default:
		return gqlerrors.FormatError(err)
	}
}

func GetGraphQLHandler(config graphql.SchemaConfig) *handler.Handler {
	schema, err := graphql.NewSchema(config)

	if err != nil {
		logger.Errorf("failed to create new schema, error: %v", err)
		return nil
	}

	h := handler.New(&handler.Config{
		Schema:   &schema,
		Pretty:   true,
		GraphiQL: true,
		CustomErrorFormatter: CustomFormat,
	})

	return h
}

@limoli
Copy link

limoli commented Oct 26, 2018

Any news? @chris-ramon
I think that this is an essential feature for a basic configuration of a response.

@limoli
Copy link

limoli commented Nov 20, 2018

Some update? @chris-ramon

@chris-ramon
Copy link
Member

Thanks a lot @racerxdl & @limoli for your great feedback, closing this one in favor of: #58

@chris-ramon chris-ramon closed this Dec 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants