import client from '../client' ; import { GraphQLResolveInfo } from 'graphql' ; import { getFlatProjectionFromAST } from 'graphql-compose' ; import { AxiosRequestConfig } from 'axios' ; export const projectionFields = [ 'userIds' ] as const ; export type _UpdateArgs = { id : string ; workschedule : Record < string , any > ; projection ? : typeof projectionFields [ number ] [ ] ; } ; export type UpdateArgs = Exclude < _UpdateArgs , 'projection' > & { info : GraphQLResolveInfo ; } ; export async function _workScheduleUpdate ( opts , context ) { const { id , workschedule , projection } = opts || { } ; const params = workschedule || { } ; if ( projection ) { if ( projection . length > 0 ) params . fields = projection ; } if ( ! id ) throw new Error ( 'You should provide `id`' ) ; const res = await client . put ( `/workschedules/${ id }` , params , context ) ; return res ?. data ?. data [ 0 ] ; } export function workScheduleUpdate ( opts , context ) { const requestedFields = Object . keys ( getFlatProjectionFromAST ( opts . info ) ) ; const projection = projectionFields . filter ( ( n ) => requestedFields . includes ( n ) ) ; return _workScheduleUpdate ( { ... opts , projection } , context ) ; }