import { GraphQLResolveInfo } from 'graphql' ; import { getFlatProjectionFromAST } from 'graphql-compose' ; import client from '../client' ; import { AxiosRequestConfig } from 'axios' ; interface ContactFilter { me ? : boolean ; deleted ? : boolean ; metadata ? : any ; } export const projectionFields = [ 'metadata' , 'workScheduleId' ] as const ; type ContactProjection = typeof projectionFields [ number ] [ ] ; type FindManyOpts = { filter ? : ContactFilter ; projection ? : ContactProjection ; } ; export async function _contactFindMany ( opts , context ) { const { filter , projection } = opts || { } ; let params = { } ; if ( filter ) { params = { ... filter } ; } if ( projection ) { if ( projection . length > 0 ) params . fields = projection ; } const res = await client . get ( '/contacts' , { ... context , params } ) ; return res ?. data ?. data ; } export function contactFindMany ( opts , context ) { const requestedFields = Object . keys ( getFlatProjectionFromAST ( opts . info ) ) ; const projection = projectionFields . filter ( ( n ) => requestedFields . includes ( n ) ) ; return _contactFindMany ( { ... opts , projection } , context ) ; }