title: Forward multipartform request from one GraphQL API to other GraphQL API
body: <p>I'm uploading files from the browser via a multipart request to a GraphQL-API which is powered by graphql-yoga which is powered by express.
  Now I want to forward this exact same request body to another GraphQL-API.</p>
  <pre><code>const fetch = require('node-fetch');
  
  async passThrough(args, opts) {
    const { body, getRawBody, headers, method } = opts.request;
    var rawBody;
    if (body.files &amp;&amp; body.files.length) {
      rawBody = await getRawBody;
    } else {
      rawBody = typeof body == 'string' ? body : JSON.stringify(body)
    }
    let options = {
      body: rawBody,
      method, headers
    };
    var res = await fetch(otherApiUrl, options).then((res) =&gt; {
      return res.json();
    });
    return res;
  }
  </code></pre>
  <p>In this function I get the body as an object. But it includes &quot;files&quot; as promises which I can't simply forward (Couldn't find anything to do it). So I tried to get the raw body through a express middleware and access it like above with <em>await getRawBody</em>.</p>
  <pre><code>function getRawBody(req, res, next) {
    req.getRawBody = new Promise(resolve =&gt; {
      var buf = '';
      req.on('data', x =&gt; buf += x);
      req.on('end', () =&gt; {
        resolve(buf);
      });
    });
    next();
  }
  
  server.express.use(getRawBody);
  </code></pre>
  <p>It passes the request to the other API but the files are no valid jpegs anymore. I found out, that the uploaded file is shifted some bits from the original file. What am I maybe doing wrong?</p>