@@ -21,7 +21,7 @@ func Create(hasura config.Hasura, cfg config.Database, views []string, models ..
2121 time .Sleep (time .Second * 10 )
2222 }
2323
24- metadata , err := Generate (cfg , models ... )
24+ metadata , err := Generate (hasura , cfg , models ... )
2525 if err != nil {
2626 return err
2727 }
@@ -80,11 +80,11 @@ func Create(hasura config.Hasura, cfg config.Database, views []string, models ..
8080}
8181
8282// Generate - creates hasura table structure in JSON from `models`. `models` should be pointer to your table models. `cfg` is DB config from YAML.
83- func Generate (cfg config.Database , models ... interface {}) (map [string ]interface {}, error ) {
83+ func Generate (hasura config. Hasura , cfg config.Database , models ... interface {}) (map [string ]interface {}, error ) {
8484 tables := make ([]interface {}, 0 )
8585 schema := getSchema (cfg )
8686 for _ , model := range models {
87- table , err := generateOne (schema , model )
87+ table , err := generateOne (hasura , schema , model )
8888 if err != nil {
8989 return nil , err
9090 }
@@ -108,7 +108,7 @@ func newTable(schema, name string) table {
108108 Name : name ,
109109 }
110110}
111- func generateOne (schema string , model interface {}) (table , error ) {
111+ func generateOne (hasura config. Hasura , schema string , model interface {}) (table , error ) {
112112 value := reflect .ValueOf (model )
113113 if value .Kind () != reflect .Ptr {
114114 return table {}, errors .Errorf ("Model has to be pointer" )
@@ -123,10 +123,10 @@ func generateOne(schema string, model interface{}) (table, error) {
123123 t .Columns = getColumns (typ )
124124
125125 if p , ok := t .HasuraSchema ["select_permissions" ]; ok {
126- t .HasuraSchema ["select_permissions" ] = append (p .([]interface {}), formatSelectPermissions (t .Columns ... ))
126+ t .HasuraSchema ["select_permissions" ] = append (p .([]interface {}), formatSelectPermissions (hasura . RowsLimit , hasura . EnableAggregations , t .Columns ... ))
127127 } else {
128128 t .HasuraSchema ["select_permissions" ] = []interface {}{
129- formatSelectPermissions (t .Columns ... ),
129+ formatSelectPermissions (hasura . RowsLimit , hasura . EnableAggregations , t .Columns ... ),
130130 }
131131 }
132132 t .HasuraSchema ["object_relationships" ] = []interface {}{}
@@ -135,13 +135,17 @@ func generateOne(schema string, model interface{}) (table, error) {
135135 return t , nil
136136}
137137
138- func formatSelectPermissions (columns ... string ) map [string ]interface {} {
138+ func formatSelectPermissions (limit uint64 , allowAggs bool , columns ... string ) map [string ]interface {} {
139+ if limit == 0 {
140+ limit = 10
141+ }
139142 return map [string ]interface {}{
140143 "role" : "user" ,
141144 "permission" : map [string ]interface {}{
142145 "columns" : columns ,
143146 "filter" : map [string ]interface {}{},
144- "allow_aggregations" : true ,
147+ "allow_aggregations" : allowAggs ,
148+ "limit" : limit ,
145149 },
146150 }
147151}
0 commit comments