Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultLogger ¶
type DefaultLogger struct{}
DefaultLogger is the default logger used to log panics that occur during query execution.
func (*DefaultLogger) LogPanic ¶
func (l *DefaultLogger) LogPanic(ctx context.Context, value interface{})
LogPanic is used to log recovered panic values that occur during query execution.
type Logger ¶
Logger is the interface used to log panics that occur during query execution. It is settable via graphql.ParseSchema.
type LoggerFunc ¶ added in v1.7.0
LoggerFunc is a function type that implements the Logger interface.
Example ¶
logfn := log.LoggerFunc(func(ctx context.Context, err interface{}) {
// Here you can handle the panic, e.g., log it or send it to an error tracking service.
fmt.Printf("graphql: panic occurred: %v", err)
})
opts := []graphql.SchemaOpt{
graphql.Logger(logfn),
graphql.UseFieldResolvers(),
}
schemadef := `
type Query {
hello: String!
}
`
resolver := &struct {
Hello func() string
}{
Hello: func() string {
// Simulate a panic
panic("something went wrong")
},
}
schema := graphql.MustParseSchema(schemadef, resolver, opts...)
// Now, when you execute a query that causes a panic, it will be logged using the provided LoggerFunc.
schema.Exec(context.Background(), "{ hello }", "", nil)
Output: graphql: panic occurred: something went wrong
func (LoggerFunc) LogPanic ¶ added in v1.7.0
func (f LoggerFunc) LogPanic(ctx context.Context, value interface{})
LogPanic calls the LoggerFunc with the given context and panic value.
Click to show internal directories.
Click to hide internal directories.