Skip to content

Commit

Permalink
add serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
kofoworola committed Oct 24, 2023
1 parent 82de2f5 commit c6e6f3a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions analytics/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const (
)

type GraphQLStats struct {
IsGraphQL bool
Types map[string][]string
OperationType GraphQLOperations
Variables string
Expand Down
32 changes: 32 additions & 0 deletions serializer/protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,37 @@ func (pb *ProtobufSerializer) TransformSingleRecordToProto(rec analytics.Analyti
ApiSchema: rec.ApiSchema,
}
rec.TimestampToProto(&record)
if rec.GraphQLStats.IsGraphQL {
// operation type
operationType := analyticsproto.GraphQLOperations_OPERATION_UNKNOWN
switch rec.GraphQLStats.OperationType {
case analytics.Operation_Query:
operationType = analyticsproto.GraphQLOperations_OPERATION_QUERY
case analytics.Operation_Mutation:
operationType = analyticsproto.GraphQLOperations_OPERATION_MUTATION
case analytics.Operation_Subscription:
operationType = analyticsproto.GraphQLOperations_OPERATION_SUBSCRIPTION
}
//graph errors
graphErrors := make([]string, len(rec.GraphQLStats.Errors))
for i, val := range rec.GraphQLStats.Errors {
graphErrors[i] = val.Message
}
// types
graphTypes := make(map[string]*analyticsproto.RepeatedFields)
for key, val := range rec.GraphQLStats.Types {
graphTypes[key] = &analyticsproto.RepeatedFields{Fields: val}
}
record.GraphQLStats = &analyticsproto.GraphQLStats{
IsGraphQL: true,
Variables: rec.GraphQLStats.Variables,
HasError: rec.GraphQLStats.HasErrors,
OperationType: operationType,
GraphErrors: graphErrors,
RootFields: rec.GraphQLStats.RootFields,
Types: graphTypes,
}
}

return record
}
Expand Down Expand Up @@ -169,6 +200,7 @@ func (pb *ProtobufSerializer) TransformSingleProtoToAnalyticsRecord(rec analytic
}

tmpRecord.GraphQLStats = analytics.GraphQLStats{
IsGraphQL: rec.GraphQLStats.IsGraphQL,
OperationType: operationType,
HasErrors: rec.GraphQLStats.HasError,
RootFields: rec.GraphQLStats.RootFields,
Expand Down

0 comments on commit c6e6f3a

Please sign in to comment.