mirror of
https://github.com/dstotijn/hetty.git
synced 2025-07-01 18:47:29 -04:00
@ -59,12 +59,12 @@ type ComplexityRoot struct {
|
||||
}
|
||||
|
||||
HTTPResponseLog struct {
|
||||
Body func(childComplexity int) int
|
||||
Headers func(childComplexity int) int
|
||||
Proto func(childComplexity int) int
|
||||
RequestID func(childComplexity int) int
|
||||
Status func(childComplexity int) int
|
||||
StatusCode func(childComplexity int) int
|
||||
Body func(childComplexity int) int
|
||||
Headers func(childComplexity int) int
|
||||
Proto func(childComplexity int) int
|
||||
RequestID func(childComplexity int) int
|
||||
StatusCode func(childComplexity int) int
|
||||
StatusReason func(childComplexity int) int
|
||||
}
|
||||
|
||||
Query struct {
|
||||
@ -191,13 +191,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||
|
||||
return e.complexity.HTTPResponseLog.RequestID(childComplexity), true
|
||||
|
||||
case "HttpResponseLog.status":
|
||||
if e.complexity.HTTPResponseLog.Status == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.HTTPResponseLog.Status(childComplexity), true
|
||||
|
||||
case "HttpResponseLog.statusCode":
|
||||
if e.complexity.HTTPResponseLog.StatusCode == nil {
|
||||
break
|
||||
@ -205,6 +198,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||
|
||||
return e.complexity.HTTPResponseLog.StatusCode(childComplexity), true
|
||||
|
||||
case "HttpResponseLog.statusReason":
|
||||
if e.complexity.HTTPResponseLog.StatusReason == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.HTTPResponseLog.StatusReason(childComplexity), true
|
||||
|
||||
case "Query.httpRequestLog":
|
||||
if e.complexity.Query.HTTPRequestLog == nil {
|
||||
break
|
||||
@ -288,8 +288,8 @@ var sources = []*ast.Source{
|
||||
type HttpResponseLog {
|
||||
requestId: ID!
|
||||
proto: String!
|
||||
status: String!
|
||||
statusCode: Int!
|
||||
statusReason: String!
|
||||
body: String
|
||||
headers: [HttpHeader!]!
|
||||
}
|
||||
@ -791,40 +791,6 @@ func (ec *executionContext) _HttpResponseLog_proto(ctx context.Context, field gr
|
||||
return ec.marshalNString2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _HttpResponseLog_status(ctx context.Context, field graphql.CollectedField, obj *HTTPResponseLog) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
fc := &graphql.FieldContext{
|
||||
Object: "HttpResponseLog",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: false,
|
||||
}
|
||||
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return obj.Status, nil
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalNString2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _HttpResponseLog_statusCode(ctx context.Context, field graphql.CollectedField, obj *HTTPResponseLog) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@ -859,6 +825,40 @@ func (ec *executionContext) _HttpResponseLog_statusCode(ctx context.Context, fie
|
||||
return ec.marshalNInt2int(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _HttpResponseLog_statusReason(ctx context.Context, field graphql.CollectedField, obj *HTTPResponseLog) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
fc := &graphql.FieldContext{
|
||||
Object: "HttpResponseLog",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: false,
|
||||
}
|
||||
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return obj.StatusReason, nil
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalNString2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _HttpResponseLog_body(ctx context.Context, field graphql.CollectedField, obj *HTTPResponseLog) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@ -2237,13 +2237,13 @@ func (ec *executionContext) _HttpResponseLog(ctx context.Context, sel ast.Select
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "status":
|
||||
out.Values[i] = ec._HttpResponseLog_status(ctx, field, obj)
|
||||
case "statusCode":
|
||||
out.Values[i] = ec._HttpResponseLog_statusCode(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "statusCode":
|
||||
out.Values[i] = ec._HttpResponseLog_statusCode(ctx, field, obj)
|
||||
case "statusReason":
|
||||
out.Values[i] = ec._HttpResponseLog_statusReason(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
|
@ -26,12 +26,12 @@ type HTTPRequestLog struct {
|
||||
}
|
||||
|
||||
type HTTPResponseLog struct {
|
||||
RequestID int64 `json:"requestId"`
|
||||
Proto string `json:"proto"`
|
||||
Status string `json:"status"`
|
||||
StatusCode int `json:"statusCode"`
|
||||
Body *string `json:"body"`
|
||||
Headers []HTTPHeader `json:"headers"`
|
||||
RequestID int64 `json:"requestId"`
|
||||
Proto string `json:"proto"`
|
||||
StatusCode int `json:"statusCode"`
|
||||
StatusReason string `json:"statusReason"`
|
||||
Body *string `json:"body"`
|
||||
Headers []HTTPHeader `json:"headers"`
|
||||
}
|
||||
|
||||
type HTTPMethod string
|
||||
|
@ -5,6 +5,7 @@ package api
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/dstotijn/hetty/pkg/reqlog"
|
||||
)
|
||||
@ -54,18 +55,21 @@ func (r *queryResolver) HTTPRequestLog(ctx context.Context, id int64) (*HTTPRequ
|
||||
|
||||
func parseRequestLog(req reqlog.Request) (HTTPRequestLog, error) {
|
||||
method := HTTPMethod(req.Request.Method)
|
||||
if !method.IsValid() {
|
||||
if method != "" && !method.IsValid() {
|
||||
return HTTPRequestLog{}, fmt.Errorf("request has invalid method: %v", method)
|
||||
}
|
||||
|
||||
log := HTTPRequestLog{
|
||||
ID: req.ID,
|
||||
URL: req.Request.URL.String(),
|
||||
Proto: req.Request.Proto,
|
||||
Method: method,
|
||||
Timestamp: req.Timestamp,
|
||||
}
|
||||
|
||||
if req.Request.URL != nil {
|
||||
log.URL = req.Request.URL.String()
|
||||
}
|
||||
|
||||
if len(req.Body) > 0 {
|
||||
reqBody := string(req.Body)
|
||||
log.Body = &reqBody
|
||||
@ -85,11 +89,14 @@ func parseRequestLog(req reqlog.Request) (HTTPRequestLog, error) {
|
||||
|
||||
if req.Response != nil {
|
||||
log.Response = &HTTPResponseLog{
|
||||
RequestID: req.ID,
|
||||
RequestID: req.Response.RequestID,
|
||||
Proto: req.Response.Response.Proto,
|
||||
Status: req.Response.Response.Status,
|
||||
StatusCode: req.Response.Response.StatusCode,
|
||||
}
|
||||
statusReasonSubs := strings.SplitN(req.Response.Response.Status, " ", 2)
|
||||
if len(statusReasonSubs) == 2 {
|
||||
log.Response.StatusReason = statusReasonSubs[1]
|
||||
}
|
||||
if len(req.Response.Body) > 0 {
|
||||
resBody := string(req.Response.Body)
|
||||
log.Response.Body = &resBody
|
||||
|
@ -12,8 +12,8 @@ type HttpRequestLog {
|
||||
type HttpResponseLog {
|
||||
requestId: ID!
|
||||
proto: String!
|
||||
status: String!
|
||||
statusCode: Int!
|
||||
statusReason: String!
|
||||
body: String
|
||||
headers: [HttpHeader!]!
|
||||
}
|
||||
|
Reference in New Issue
Block a user