import type { Plugin } from "graphile-build" ; import type { PgClass } from "graphile-build-pg" ; const AddGroupByAggregateEnumsPlugin = ( builder ) => { builder . hook ( "init" , ( _ , build ) => { const { newWithHooks , pgIntrospectionResultsByKind : introspectionResultsByKind , graphql : { GraphQLEnumType } , inflection , pgOmit : omit , sqlCommentByAddingTags , describePgEntity , } = build ; introspectionResultsByKind . class . forEach ( ( table ) => { if ( ! table . isSelectable || omit ( table , "order" ) ) return ; if ( ! table . namespace ) return ; const tableTypeName = inflection . tableType ( table ) ; newWithHooks ( GraphQLEnumType , { name : inflection . aggregateGroupByType ( table ) , description : build . wrapDescription ( `Grouping methods for \`${ tableTypeName }\` for usage during aggregation.` , "type" ) , values : { } , } , { __origin : `Adding connection "groupBy" enum type for ${ describePgEntity ( table ) }. You can rename the table's GraphQL type via a 'Smart Comment':\n\n  ${ sqlCommentByAddingTags ( table , { name : "newNameHere" , } ) }` , pgIntrospection : table , isPgAggregateGroupEnum : true , } , true ) ; } ) ; return _ ; } , [ "AddGroupByAggregateEnumsPlugin" ] ) ; } ; export default AddGroupByAggregateEnumsPlugin ;