How to use the apollo-server-core.processFileUploads function in apollo-server-core

To help you get started, we’ve selected a few apollo-server-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apollographql / apollo-server / packages / apollo-server-fastify / src / ApolloServer.ts View on Github external
) => (
  req: FastifyRequest,
  reply: FastifyReply,
  done: (err: Error | null, body?: any) => void,
) => {
  if (
    (req.req as any)[kMultipart] &&
    typeof processFileUploads === 'function'
  ) {
    processFileUploads(req.req, reply.res, uploadsConfig)
      .then((body: GraphQLOperation | GraphQLOperation[]) => {
        req.body = body;
        done(null);
      })
      .catch((error: any) => {
        if (error.status && error.expose) reply.status(error.status);

        throw formatApolloErrors([error], {
          formatter: server.requestOptions.formatError,
          debug: server.requestOptions.debug,
        });
      });
  } else {
    done(null);
  }
};
github apollographql / apollo-server / packages / apollo-server-hapi / src / ApolloServer.ts View on Github external
return async (request: hapi.Request, _h?: hapi.ResponseToolkit) => {
    if (
      typeof processFileUploads === 'function' &&
      request.mime === 'multipart/form-data'
    ) {
      Object.defineProperty(request, 'payload', {
        value: await processFileUploads(
          request.raw.req,
          request.raw.res,
          uploadsConfig,
        ),
        writable: false,
      });
    }
  };
}
github apollographql / apollo-server / packages / apollo-server-koa / src / ApolloServer.ts View on Github external
) => async (ctx: Koa.Context, next: Function) => {
  if (typeis(ctx.req, ['multipart/form-data'])) {
    try {
      ctx.request.body = await processFileUploads(
        ctx.req,
        ctx.res,
        uploadsConfig,
      );
      return next();
    } catch (error) {
      if (error.status && error.expose) ctx.status = error.status;

      throw formatApolloErrors([error], {
        formatter: server.requestOptions.formatError,
        debug: server.requestOptions.debug,
      });
    }
  } else {
    return next();
  }