import { inject } from '@angular/core';
import type { ApolloLink, DefaultContext } from '@apollo/client/core';
import { Apollo } from 'apollo-angular';
import type { DocumentNode } from 'graphql';
import type { Observable } from 'rxjs';

export function mutateInsert(
  mutation: DocumentNode,
  payload: Record<string, unknown>[],
  headers?: Record<string, string>,
): Observable<ApolloLink.Result<Record<string, unknown>>> {
  const apollo = inject(Apollo);
  return apollo.mutate<Record<string, unknown>>({
    mutation,
    variables: { payload },
    context: { headers } as DefaultContext,
  });
}
