Skip to content

Commit

Permalink
followup fix (#1389)
Browse files Browse the repository at this point in the history
  • Loading branch information
lolopinto committed Mar 15, 2023
1 parent 41ffbb7 commit 01bf6fc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
17 changes: 10 additions & 7 deletions internal/schema/node_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,9 @@ type entLoadPrivacyInfo struct {
Fields []*field.Field
}

func (nodeData *NodeData) GetOnEntLoadPrivacyInfo(cfg codegenapi.Config) (*entLoadPrivacyInfo, error) {
func (nodeData *NodeData) GetOnEntLoadPrivacyInfo(cfg codegenapi.Config) *entLoadPrivacyInfo {
if !nodeData.OnEntLoadFieldPrivacy(cfg) {
return nil, fmt.Errorf("cannot call GetOnEntLoadPrivacyInfo for node which doesn't use on ent load privacy")
return nil
}

var fields []*field.Field
Expand All @@ -546,13 +546,16 @@ func (nodeData *NodeData) GetOnEntLoadPrivacyInfo(cfg codegenapi.Config) (*entLo
}
}

ret := &entLoadPrivacyInfo{
Interface: fmt.Sprintf("%sData", nodeData.Node),
Extends: fmt.Sprintf("Omit<%s, %s>", nodeData.GetRawDBDataName(), strings.Join(names, " | ")),
Fields: fields,
if len(fields) != 0 {
ret := &entLoadPrivacyInfo{
Interface: fmt.Sprintf("%sData", nodeData.Node),
Extends: fmt.Sprintf("Omit<%s, %s>", nodeData.GetRawDBDataName(), strings.Join(names, " | ")),
Fields: fields,
}
return ret
}

return ret, nil
return nil
}

type extraCustomQueryInfo struct {
Expand Down
6 changes: 3 additions & 3 deletions internal/tscode/base.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@
{{$dataType := $rawDBDataType -}}
{{$customQueryDataType := $rawDBDataType -}}

{{if .OnEntLoadFieldPrivacy $cfg -}}
{{$info := .GetOnEntLoadPrivacyInfo $cfg -}}
{{$info := .GetOnEntLoadPrivacyInfo $cfg -}}
{{ if $info -}}
{{$dataType = $info.Interface -}}
interface {{$info.Interface}} extends {{$info.Extends}} {
{{range $field := $info.Fields -}}
{{$field.GetDbColName}}: {{$field.TsType}};
{{ end -}}
}
{{ end -}}
{{end}}

{{ $customQuery := .GetExtraCustomQueryInfo -}}
{{ if $customQuery -}}
Expand Down

0 comments on commit 01bf6fc

Please sign in to comment.