@agrian/apollo-federation-upload-minimal
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Apollo Federation file upload

This is a minimally changed fork of apollo-federation-file-upload configured to use graphql-upload-minimal instead of graphql-upload.

This library makes it easier to support file uploads to your federated micro-services. It uses the Apollo server's solution. It works by simply redirecting the file uploaded stream to the micro-service. This package does not use third-party services to send the package to your micro-services.

Apollo Federation V2 Support

Please, use version 4.0.0+. For Federation V1 use 3.0.0 or earlier.

Using HTTP Transfer-Encoding: chunked

By default, the FileUploadDataSource uses chunked transfers; we advise that you do not change this setup. However, for some reason you can't support this kind of transfer, one can provide the useChunkedTransfer option to the FileUploadDataSource constructor as false to not use chunked transfer (See the example below on setting this property). Be advised once again that this can lead to DDOS attacks.

Example

On your Gateway, you must add the FileUploadDataSource in order to the micro-service be able to receive the uploaded file(s).

import { ApolloServer } from 'apollo-server';
import { ApolloGateway } from '@apollo/gateway';
import FileUploadDataSource from '@profusion/apollo-federation-upload';

const runServer = async () => {
  const server = new ApolloServer({
    gateway: new ApolloGateway({
      // Add this line in order to support file uploads.
      buildService: ({ url }) => new FileUploadDataSource({ url, useChunkedTransfer: true }),
      serviceList: [
        /* The services ... */
      ],
    })
  });

  const { url } = await server.listen();

  console.log(`🚀  Server ready at ${url}`);
};

runServer().catch(error => {
  console.error('💥  Failed to start server:', error);
  process.exit(1);
});

Package Sidebar

Install

npm i @agrian/apollo-federation-upload-minimal

Weekly Downloads

25

Version

1.0.0

License

MIT

Unpacked Size

15 kB

Total Files

12

Last publish

Collaborators

  • grire974tac
  • malexandru398
  • olegsyngt
  • scott_rippee_agrian
  • chrisnik
  • nick_agrian
  • bruceferguson3
  • troy.lonie
  • krishnabreddy
  • imrahl
  • cajr11
  • ish.tahir
  • kurtronshausen
  • rockenfels
  • bwilson-agrian
  • agrian_steve
  • rickburke
  • sujin_agrian
  • teamcity_agrian
  • randyagrian
  • mrunleaded
  • palhash
  • bstrait
  • dipilagrian
  • mirela.cicioc
  • ktwl
  • dustintidymanjones
  • brisc
  • owenlevin
  • robertpbaxter
  • parker-nalch
  • cyang023