Skip to content

Commit 9da30c8

Browse files
committed
fix compiler
1 parent c13bedf commit 9da30c8

File tree

10 files changed

+318
-212
lines changed

10 files changed

+318
-212
lines changed

_examples/02_simple/federation/federation.pb.go

Lines changed: 154 additions & 151 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_examples/02_simple/federation/federation_grpc_federation.pb.go

Lines changed: 80 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_examples/02_simple/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ require (
3636
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
3737
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // indirect
3838
golang.org/x/net v0.38.0 // indirect
39-
golang.org/x/sync v0.14.0 // indirect
39+
golang.org/x/sync v0.15.0 // indirect
4040
golang.org/x/sys v0.31.0 // indirect
41-
golang.org/x/text v0.23.0 // indirect
41+
golang.org/x/text v0.26.0 // indirect
4242
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 // indirect
4343
)

_examples/02_simple/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 h1:y5zboxd6LQAqYIhHnB48p0ByQ
6262
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6/go.mod h1:U6Lno4MTRCDY+Ba7aCcauB9T60gsv5s4ralQzP72ZoQ=
6363
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
6464
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
65-
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
66-
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
65+
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
66+
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
6767
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
6868
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
69-
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
70-
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
69+
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
70+
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
7171
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 h1:YcyjlL1PRr2Q17/I0dPk2JmYS5CDXfcdb2Z3YRioEbw=
7272
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7/go.mod h1:OCdP9MfskevB/rbYvHTsXTtKC+3bHWajPdoKgjcYkfo=
7373
google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7 h1:2035KHhUv+EpyB+hWgJnaWKJOdX1E95w2S8Rr4uWKTs=

_examples/02_simple/proto/federation/federation.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ message GetPostResponse {
5454
def { name: "floor" by: "grpc.federation.math.floor(1.51)" }
5555
def { name: "flatten" by: "[[1], [2], [3]].flatten()" }
5656
def { name: "round" by: "grpc.federation.math.round(1.5)" }
57+
def { name: "dup" by: "[1, 2, 3, 4].filter(dup, dup % 2 == 0)"}
5758
};
5859
Post post = 1 [(grpc.federation.field).by = "post"];
5960
string str = 2 [(grpc.federation.field).by = "'hello'"];

resolver/graph.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,11 @@ func setupVariableDependencyByReferenceName(nodes []*MessageDependencyGraphNode)
330330
nameToNode := make(map[string]*MessageDependencyGraphNode)
331331
for _, node := range nodes {
332332
def := node.VariableDefinition
333-
if def.Name != "" {
334-
nameToNode[def.Name] = node
335-
}
336-
337333
refs := def.ReferenceNames()
338334
if len(refs) == 0 {
335+
if def.Name != "" {
336+
nameToNode[def.Name] = node
337+
}
339338
continue
340339
}
341340
var iterName string
@@ -361,6 +360,9 @@ func setupVariableDependencyByReferenceName(nodes []*MessageDependencyGraphNode)
361360
node.ParentMap[refNode] = struct{}{}
362361
}
363362
}
363+
if def.Name != "" {
364+
nameToNode[def.Name] = node
365+
}
364366
}
365367
}
366368

resolver/resolver.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,6 +2689,14 @@ func (r *Resolver) resolveCallExpr(ctx *context, def *federation.CallExpr, build
26892689

26902690
func (r *Resolver) resolveValidationExpr(ctx *context, def *federation.ValidationExpr, builder *source.ValidationExprOptionBuilder) *ValidationExpr {
26912691
grpcErr := r.resolveGRPCError(ctx, def.GetError(), builder.WithError())
2692+
if grpcErr.Code == nil {
2693+
ctx.addError(
2694+
ErrWithLocation(
2695+
`"code" field is required in validation`,
2696+
builder.WithError().Location(),
2697+
),
2698+
)
2699+
}
26922700
if grpcErr.Ignore {
26932701
ctx.addError(
26942702
ErrWithLocation(

resolver/value.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ func (v *CELValue) ReferenceNames() []string {
3030
}
3131

3232
var refNames []string
33+
iterVarMap := make(map[string]struct{})
34+
if cmp := v.CheckedExpr.GetExpr().GetComprehensionExpr(); cmp != nil {
35+
if iterVar := cmp.GetIterVar(); iterVar != "" {
36+
iterVarMap[iterVar] = struct{}{}
37+
}
38+
if iterVar := cmp.GetIterVar2(); iterVar != "" {
39+
iterVarMap[iterVar] = struct{}{}
40+
}
41+
}
3342
for _, ref := range v.CheckedExpr.ReferenceMap {
3443
if ref.Name == federation.MessageArgumentVariableName {
3544
continue
@@ -38,6 +47,9 @@ func (v *CELValue) ReferenceNames() []string {
3847
if ref.Name == "" {
3948
continue
4049
}
50+
if _, exists := iterVarMap[ref.Name]; exists {
51+
continue
52+
}
4153
refNames = append(refNames, ref.Name)
4254
}
4355
return refNames
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
syntax = "proto3";
2+
3+
package federation;
4+
5+
import "federation.proto";
6+
7+
option go_package = "example/federation;federation";
8+
9+
service FederationService {
10+
option (grpc.federation.service) = {};
11+
rpc GetPost(GetPostRequest) returns (GetPostResponse) {};
12+
}
13+
14+
message GetPostRequest {
15+
string id = 1;
16+
}
17+
18+
message GetPostResponse {
19+
option (grpc.federation.message) = {
20+
def [
21+
{
22+
validation {
23+
error {
24+
if: "true"
25+
message: "'error'"
26+
}
27+
}
28+
}
29+
]
30+
};
31+
}

validator/validator_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ different_message_argument_type.proto:28:14: "id" argument name is declared with
3636
^
3737
`},
3838
{file: "duplicated_variable_name.proto", expected: `
39+
duplicated_variable_name.proto:26:17: "code" field is required in validation
40+
26: error {
41+
^
3942
duplicated_variable_name.proto:27:25: found duplicated variable name "a"
4043
27: def { name: "a" by: "1" }
4144
^
@@ -182,6 +185,9 @@ invalid_error_variable.proto:21:25: ERROR: <input>:1:1: undeclared reference to
182185
| ^
183186
21: def { name: "e" by: "error" }
184187
^
188+
invalid_error_variable.proto:24:15: "code" field is required in validation
189+
24: error {
190+
^
185191
invalid_error_variable.proto:25:15: ERROR: <input>:1:1: undeclared reference to 'error' (in container 'org.federation')
186192
| error.code == 0
187193
| ^
@@ -660,6 +666,9 @@ nested_message_cyclic_dependency.proto:55:19: recursive definition: "C" is own m
660666
invalid_variable_name.proto:22:15: "_def0" is invalid name. name should be in the following pattern: ^[a-zA-Z][a-zA-Z0-9_]*$
661667
22: { name: "_def0" by: "0" },
662668
^
669+
invalid_variable_name.proto:25:17: "code" field is required in validation
670+
25: error {
671+
^
663672
invalid_variable_name.proto:26:25: "_def1" is invalid name. name should be in the following pattern: ^[a-zA-Z][a-zA-Z0-9_]*$
664673
26: def { name: "_def1" by: "1" }
665674
^
@@ -731,6 +740,11 @@ invalid_wrapper_type_conversion.proto:47:3: cannot convert type automatically: f
731740
invalid_wrapper_type_conversion.proto:48:3: cannot convert type automatically: field type is "message" but specified value type is "bytes"
732741
48: google.protobuf.BytesValue bytes_wrapper_value2 = 27 [(grpc.federation.field).by = "bytes('world')"];
733742
^
743+
`},
744+
{file: "invalid_validation_code.proto", expected: `
745+
invalid_validation_code.proto:23:17: "code" field is required in validation
746+
23: error {
747+
^
734748
`},
735749
{file: "invalid_validation_return_type.proto", expected: `
736750
invalid_validation_return_type.proto:50:17: if must always return a boolean value
@@ -774,9 +788,15 @@ invalid_validation_localized_message.proto:54:26: message must always return a s
774788
^
775789
`},
776790
{file: "invalid_validation_with_ignore.proto", expected: `
791+
invalid_validation_with_ignore.proto:22:15: "code" field is required in validation
792+
22: error {
793+
^
777794
invalid_validation_with_ignore.proto:24:19: validation doesn't support "ignore" feature
778795
24: ignore: true
779796
^
797+
invalid_validation_with_ignore.proto:30:15: "code" field is required in validation
798+
30: error {
799+
^
780800
invalid_validation_with_ignore.proto:32:32: validation doesn't support "ignore_and_response" feature
781801
32: ignore_and_response: "'foo'"
782802
^

0 commit comments

Comments
 (0)