Support for GraphQL #663
Unanswered
vikivenkat
asked this question in
Q&A
Replies: 1 comment
-
If you're exposing the GraphQL API with ASP NET CORE MVC, you should be able to use Audit.WebApi.Core library and configure the audit middleware. For example: public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddGraphQL(...);
// ...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// configure the audit output
Audit.Core.Configuration.Setup()
.UseFileLogProvider(_ => _.Directory(@"C:\Logs"));
// allow auditing the request body
app.Use(async (context, next) =>
{
context.Request.EnableBuffering();
await next();
});
// Configure the audit input
app.UseAuditMiddleware(_ => _
.FilterByRequest(rq => rq.Path.Value.Contains("/api/graphql"))
.WithEventType("{verb}:{url}")
.IncludeRequestBody()
.IncludeResponseBody());
// ...
}
} And you should see audit logs like this: {
"Action": {
"TraceId": "0HN300LAQNUOQ:00000002",
"HttpMethod": "POST",
"RequestUrl": "http://localhost:3000/api/graphql",
"IpAddress": "::1",
"ResponseStatus": "OK",
"ResponseStatusCode": 200,
"RequestBody": {
"Type": "application/json",
"Length": 911,
"Value": "{\"query\": {...} }"
},
"ResponseBody": {
"Type": "application/json",
"Value": "{\"data\":{\"human\":{\"id\":\"1\",\"name\":\"Luke\"}}}"
}
},
"EventType": "POST:http://localhost:3000/api/graphql",
"StartDate": "2024-04-19T00:12:10.4488031Z",
"EndDate": "2024-04-19T00:12:10.5060457Z",
"Duration": 57
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Does Audit.NET have support for GraphQL? How can we log requests to GraphQL endpoints?
Beta Was this translation helpful? Give feedback.
All reactions