import client from '../client' ; import { GraphQLResolveInfo } from 'graphql' ; import { getFlatProjectionFromAST } from 'graphql-compose' ; import { AxiosRequestConfig } from 'axios' ; type CommentFindFilter = { createdDate ? : { start : Date ; end : Date ; } ; folderId ? : string ; taskId ? : string ; } ; export type FindManyOpts = { withUrls ? : boolean ; versions ? : boolean ; filter ? : CommentFindFilter ; } ; export async function _attachmentFindMany ( opts , context ) { const { filter , withUrls , versions } = opts || { } ; let params = { } ; const { folderId , taskId , ... restFilter } = filter || { } ; if ( restFilter ) { params = { ... restFilter , withUrls : ! ! withUrls , versions : ! ! versions } ; } let url = '/attachments' ; if ( folderId ) { url = `/folders/${ folderId }/attachments` ; } else if ( taskId ) { url = `/tasks/${ taskId }/attachments` ; } const res = await client . get ( url , { ... context , params } ) ; return res ?. data ?. data ; } export function attachmentFindMany ( opts , context ) { const requestedFields = Object . keys ( getFlatProjectionFromAST ( opts . info ) ) ; const withUrls = requestedFields . includes ( 'url' ) ; return _attachmentFindMany ( { ... opts , withUrls } , context ) ; }