Ent: Add support for additional fields in Connection objects

Created on 2 Dec 2020  路  4Comments  路  Source: ent/ent

Hi @a8m,

We need to add additional fields to generated connect objects by pagination template.
https://github.com/facebookincubator/ent-contrib/blob/master/entgql/template/pagination.tmpl

{{/* A template for adding additional fields to specific types. */}}
{{ define "model/fields/additional" }}
    {{- /* Add static fields to the "Card" entity. */}}
    {{- if eq $.Name "Card" }}
        // StaticField defined by templates.
        StaticField string `json:"static_field,omitempty"`
    {{- end }}
{{ end }}

Just like above if you can add support to override a template to add more fields to the connections object then it will help us to extend them as per our needs.

Thanks,
Dilip

Most helpful comment

Great @dilipkk-foyernet.

Feel free to share your workaround for future readers. Thanks 馃槉

All 4 comments

Solved using a different approach so this is not needed at this moment.

Great @dilipkk-foyernet.

Feel free to share your workaround for future readers. Thanks 馃槉

// DeviceConnection is for constructing device search response
type DeviceConnection struct {
    *ent.DeviceConnection
    CountByType []*DeviceCountByType
}

I am extending ent connection object and adding custom fields.

@a8m if you have time then can you tell me what I am doing wrong here: https://github.com/facebookincubator/ent-contrib/pull/19, just for my understanding. Thanks for your support as always :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ernado picture ernado  路  3Comments

ernado picture ernado  路  4Comments

kkom picture kkom  路  3Comments

a8m picture a8m  路  5Comments

dom3k picture dom3k  路  4Comments