sibelius
7/22/2018 - 1:57 PM

Using FormData to make a GraphQL Request

Using FormData to make a GraphQL Request

function getRequestBodyWithUploadables(request, variables, uploadables) {
  let formData = new FormData();
  formData.append('query', request.text);
  formData.append('variables', JSON.stringify(variables));

  Object.keys(uploadables).forEach(key => {
    if (Object.prototype.hasOwnProperty.call(uploadables, key)) {
      formData.append(key, uploadables[key]);
    }
  });

  return formData;
}