From 2e56a5dfb08af356b3898b7f576b519d75e18bd0 Mon Sep 17 00:00:00 2001 From: xqbumu Date: Mon, 18 Mar 2024 15:34:40 +0800 Subject: [PATCH 1/2] fix: add edges ids function --- entproto/cmd/protoc-gen-entgrpc/template/method_mutate.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entproto/cmd/protoc-gen-entgrpc/template/method_mutate.tmpl b/entproto/cmd/protoc-gen-entgrpc/template/method_mutate.tmpl index b68f8a86f..83b5c232b 100644 --- a/entproto/cmd/protoc-gen-entgrpc/template/method_mutate.tmpl +++ b/entproto/cmd/protoc-gen-entgrpc/template/method_mutate.tmpl @@ -81,7 +81,7 @@ {{- $varName := camel .EntEdge.StructField }} {{- $id := printf "item.Get%s()" .EdgeIDPbStructField }} {{- template "field_to_ent" dict "Field" . "VarName" $varName "Ident" $id }} - m.Add{{ singular .EntEdge.StructField }}IDs({{ $varName }}) + m.{{ .EntEdge.MutationAdd }}({{ $varName }}) } {{- end }} {{- end }} From c0ddd2b2c6bf1f673fb99ff551002fcf42402b58 Mon Sep 17 00:00:00 2001 From: xqbumu Date: Tue, 19 Mar 2024 10:16:10 +0800 Subject: [PATCH 2/2] chore: add grpc edge immutable check for update --- .../template/method_mutate.tmpl | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/entproto/cmd/protoc-gen-entgrpc/template/method_mutate.tmpl b/entproto/cmd/protoc-gen-entgrpc/template/method_mutate.tmpl index 83b5c232b..954b0f47a 100644 --- a/entproto/cmd/protoc-gen-entgrpc/template/method_mutate.tmpl +++ b/entproto/cmd/protoc-gen-entgrpc/template/method_mutate.tmpl @@ -68,21 +68,24 @@ {{- end }} {{- end }} {{- range .G.FieldMap.Edges }} - {{- if .EntEdge.Unique }} - {{- $varName := camel (printf "%s_%s" $reqVar .EntEdge.Name) -}} - {{- $id := printf "%s.Get%s().Get%s()" $reqVar .PbStructField .EdgeIDPbStructField }} - {{- $other := printf "%s.Get%s()" $reqVar .PbStructField }} - if {{ $other }} != nil { - {{- template "field_to_ent" dict "Field" . "VarName" $varName "Ident" $id }} - m.Set{{ .EntEdge.StructField }}ID({{ $varName }}) - } - {{- else }} - for _, item := range {{ $reqVar }}.Get{{ .PbStructField }}() { - {{- $varName := camel .EntEdge.StructField }} - {{- $id := printf "item.Get%s()" .EdgeIDPbStructField }} - {{- template "field_to_ent" dict "Field" . "VarName" $varName "Ident" $id }} - m.{{ .EntEdge.MutationAdd }}({{ $varName }}) - } + {{- $skipImmutable := and ( eq $methodName "Update" ) .EntEdge.Immutable -}} + {{- if not $skipImmutable }} + {{- if .EntEdge.Unique }} + {{- $varName := camel (printf "%s_%s" $reqVar .EntEdge.Name) -}} + {{- $id := printf "%s.Get%s().Get%s()" $reqVar .PbStructField .EdgeIDPbStructField }} + {{- $other := printf "%s.Get%s()" $reqVar .PbStructField }} + if {{ $other }} != nil { + {{- template "field_to_ent" dict "Field" . "VarName" $varName "Ident" $id }} + m.Set{{ .EntEdge.StructField }}ID({{ $varName }}) + } + {{- else }} + for _, item := range {{ $reqVar }}.Get{{ .PbStructField }}() { + {{- $varName := camel .EntEdge.StructField }} + {{- $id := printf "item.Get%s()" .EdgeIDPbStructField }} + {{- template "field_to_ent" dict "Field" . "VarName" $varName "Ident" $id }} + m.{{ .EntEdge.MutationAdd }}({{ $varName }}) + } + {{- end }} {{- end }} {{- end }} {{ end }} \ No newline at end of file