Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Log every graphql request #1357

Closed
mg98 opened this issue Oct 11, 2020 · 1 comment
Closed

Log every graphql request #1357

mg98 opened this issue Oct 11, 2020 · 1 comment

Comments

@mg98
Copy link

mg98 commented Oct 11, 2020

I wanted to ask if there is a convenient way to log all incoming graphql api requests. The middleware function could be a way, but I think there's not really a nice way to get information like the graphql path and the inputs etc.

I would like to do something in a similar fashion that I've implemented to log errors:

rootHandler.SetErrorPresenter(func(ctx context.Context, e error) *gqlerror.Error {
	err := graphql.DefaultErrorPresenter(ctx, e)
	logger.Debugw("graphql request failed",
		"message", err.Message,
		"path", err.Path,
		"locations", err.Locations,
		"extensions", err.Extensions,
		"rule", err.Rule,
	)
	
	return err
})
@rschmied
Copy link

this prints every request coming in.

gqlsrv.AroundOperations(func(ctx context.Context, next graphql.OperationHandler) graphql.ResponseHandler {
	oc := graphql.GetOperationContext(ctx)
	fmt.Printf("around: %s %s", oc.OperationName, oc.RawQuery)
	return next(ctx)
})

@frederikhors frederikhors converted this issue into discussion #1816 Jan 19, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants