import { DataType } from "@sankhyalabs/core";
import { DataFetcher } from "../DataFetcher";
import { DataUnitTransient } from "@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";
export class GraphQLRecaller {
  constructor(req, resolve, reject) {
    this.req = req;
    this.resolve = resolve;
    this.reject = reject;
  }
  putVariable(name, value) {
    this.req.values[name] = value;
  }
  reCall() {
    return DataFetcher.get().callGraphQL(this.req).then(this.resolve, this.reject);
  }
  putTXPro(name, value) {
    if (!this.req || !this.req.values)
      return;
    const changes = this.req.values.changes || [];
    if (changes.length) {
      this.req.values.changes[0].fields.push({
        dataType: DataType.TEXT,
        fieldName: `${DataUnitTransient.DATA_UNIT_TRANSIENT_PREFIX_NAME}${name}`,
        value
      });
    }
  }
}
