Enhances Apollo for intuitive file uploads via GraphQL queries or mutations. Use with apollo-upload-client.
Install with peer dependencies using npm:
npm install apollo-upload-server graphql
Add the middleware just before graphql-server.
maxFieldSize(integer): Max allowed non-file multipart form field size in bytes; enough for your queries (default: 1 MB).maxFileSize(integer): Max allowed file size in bytes (default: Infinity).maxFiles(integer): Max allowed number of files (default: Infinity).
import { apolloUploadKoa } from 'apollo-upload-server'
// …
router.post(
'/graphql',
koaBody(),
apolloUploadKoa(/* Options */),
graphqlKoa(/* … */)
)import { apolloUploadExpress } from 'apollo-upload-server'
// …
app.use(
'/graphql',
bodyParser.json(),
apolloUploadExpress(/* Options */),
graphqlExpress(/* … */)
)To make your own middleware import the processRequest async function:
import { processRequest } from 'apollo-upload-server'A file upload promise that resolves an object containing:
streamfilenamemimetypeencoding
It must be added to your types and resolvers:
import { makeExecutableSchema } from 'graphql-tools'
import { GraphQLUpload } from 'apollo-upload-server'
const schema = makeExecutableSchema({
typeDefs: [`scalar Upload`],
resolvers: {
Upload: GraphQLUpload
}
})Also setup apollo-upload-client.
Once setup, on the client use FileList, File and ReactNativeFile instances anywhere within query or mutation input variables. See the client usage.
Files upload via a GraphQL multipart request and appear as Upload scalars in resolver arguments.
See the example API and client.
See package.json engines.