import type { PgAttribute , PgClass , PgConstraint , PgProc , } from "graphile-build-pg" ; import { makeAddInflectorsPlugin } from "graphile-utils" ; import { AggregateGroupBySpec , AggregateSpec } from "./interfaces" ; type Keys = Array < { column : string ; table : string ; schema ? : string ; } > ; export default makeAddInflectorsPlugin ( { aggregateContainerType ( table ) { return this . upperCamelCase ( `${ this . _singularizedTableName ( table ) }-aggregates` ) ; } , aggregateType ( table , aggregateSpec ) { return this . upperCamelCase ( `${ this . _singularizedTableName ( table ) }-${ aggregateSpec . id }-aggregates` ) ; } , aggregatesContainerField ( _table ) { return "aggregates" ; } , groupedAggregatesContainerField ( _table ) { return "groupedAggregates" ; } , aggregatesField ( aggregateSpec ) { return aggregateSpec . id ; } , aggregateGroupByType ( table ) { return this . upperCamelCase ( `${ this . _tableName ( table ) }-group-by` ) ; } , aggregateGroupByColumnEnum ( attr ) { return this . constantCase ( `${ this . _columnName ( attr ) }` ) ; } , aggregateHavingInputType ( table ) { return this . upperCamelCase ( `${ this . _tableName ( table ) }-having-input` ) ; } , aggregateHavingAggregateInputType ( table , aggregateSpec ) { return this . upperCamelCase ( `${ this . _tableName ( table ) }-having-${ aggregateSpec . id }-input` ) ; } , aggregateHavingAggregateComputedColumnInputType ( table , aggregateSpec , proc ) { return this . upperCamelCase ( `${ this . _tableName ( table ) }-having-${ aggregateSpec . id }-${ proc . name }-input` ) ; } , aggregateHavingAggregateComputedColumnArgsInputType ( table , aggregateSpec , proc ) { return this . upperCamelCase ( `${ this . _tableName ( table ) }-having-${ aggregateSpec . id }-${ proc . name }-args-input` ) ; } , aggregateGroupByColumnDerivativeEnum ( attr , spec ) { return this . constantCase ( `${ this . _columnName ( attr ) }-${ spec . id }` ) ; } , orderByCountOfManyRelationByKeys ( detailedKeys , table , foreignTable , constraint ) { const relationName = this . manyRelationByKeys ( detailedKeys , table , foreignTable , constraint ) ; return this . constantCase ( `${ relationName }-count` ) ; } , orderByColumnAggregateOfManyRelationByKeys ( detailedKeys , table , foreignTable , constraint , aggregateSpec , column ) { const relationName = this . manyRelationByKeys ( detailedKeys , table , foreignTable , constraint ) ; return this . constantCase ( `${ relationName }-${ aggregateSpec . id }-${ this . _columnName ( column ) }` ) ; } , } ) ;