🚀 Features
1. Dgraph Migration Support
- Added native migration capabilities for Dgraph through new methods, enabling precise schema evolution:
// Apply or update the complete Dgraph schema ApplySchema(ctx context.Context, schema string) error // Atomically create or update a field definition AddOrUpdateField(ctx context.Context, fieldName, fieldType, directives string) error // Permanently remove a field/predicate and its associated data DropField(ctx context.Context, fieldName string) error
- Refer to the official documentation for full usage details.
🛠 Improvements
1. gRPC Server Configuration via AddGRPCServerOptions
-
GoFr now allows configuring advanced gRPC
ServerOptions
. -
Example: Enabling TLS and setting a connection timeout
creds, _ := credentials.NewServerTLSFromFile("server-cert.pem", "server-key.pem") app.AddGRPCServerOptions( grpc.Creds(creds), grpc.ConnectionTimeout(10*time.Second), )
-
Refer to the official documentation to know more.
2. Add Custom Unary Interceptors
app.AddGRPCUnaryInterceptors(authInterceptor)
-
GoFr already logs, traces and sends default metrics for all gRPC calls. No external interceptor for such features is necessary. Custom server-side
UnaryServerInterceptors
can now be registered easily for use cases like:- Authentication
- Request validation
-
For guidance on how to define Server UnaryInterceptors that can be added in your GoFr's gRPC server, check out the official documentation.
3. Advanced gRPC Client DialOptions Support
-
Clients can now be customized extensively via
grpc.DialOptions
.
This allows to add gRPC services with :
- Secure TLS communication
- Load-balanced connections
- Retry logic
- Context-aware metadata injection (useful for tracing and auth)const serviceConfig = `{ "loadBalancingPolicy": "round_robin", "methodConfig": [{ "name": [{"service": "HelloService"}], "retryPolicy": { "maxAttempts": 4, "initialBackoff": "0.1s", "maxBackoff": "1s", "backoffMultiplier": 2.0, "retryableStatusCodes": ["UNAVAILABLE", "RESOURCE_EXHAUSTED"] } }] }` // Metadata interceptor to add client ID to each request func MetadataUnaryInterceptor(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption, ) error { md := metadata.Pairs("client-id", "f1b1a372-02f5-4065-9ccf-113d34a3d5ed") ctx = metadata.NewOutgoingContext(ctx, md) return invoker(ctx, method, req, reply, cc, opts...) } func main() { app := gofr.New() creds, err := credentials.NewClientTLSFromFile("cert.pem", "") if err != nil { app.Logger().Errorf("TLS error: %v", err) return } grpcClient, err := client.NewHelloServiceGoFrClient( app.Config.Get("GRPC_SERVER_HOST"), app.Metrics(), grpc.WithTransportCredentials(creds), grpc.WithDefaultServiceConfig(serviceConfig), grpc.WithChainUnaryInterceptor(MetadataUnaryInterceptor), ) if err != nil { app.Logger().Errorf("Failed to create client: %v", err) return } handler := NewGreetHandler(grpcClient) app.GET("/hello", handler.Hello) app.Run() }
- Refer to the official documentation to know more.
🛠 Fixes
1. SurrealDB Update
Method: Unexpected Behavior Fixed
- Regardless of the input, the
Update
method previously inserted an unexpected hardcoded key-value pair. The method now correctly updates only the intended fields as passed by the caller.