⚠️
This is the documentation for the old GraphQL Mesh version v0. We recommend upgrading to the latest GraphQL Mesh version v1.
Migrate to GraphQL Mesh v1
Migrate to GraphQL Mesh v1
File uploads
Thanks to its server based on GraphQL Yoga, GraphQL Mesh provides file upload support out of the box.
Similarly, just a few configuration changes will be necessary to forward file uploads to Sources.
Sources file uploads
The following Gateway integrates a “UploadFiles” Source that has file upload capabilities:
You will find the complete example in
examples/graphql-file-upload-example/.meshrc.yml
.
Custom resolvers file uploads
Custom resolvers, programmatically provided by additionalResolvers
, can also support File uploads
(ex: upload to S3).
For this, the only configuration step would be to define the File
scalar to enable file uploads
and our file upload Mutation:
.meshrc.yaml
sources:
# …
transforms:
# …
additionalTypeDefs: |
scalar File
extend type Mutation {
uploadFile(upload: File!): FileResult!
}
additionalResolvers:
- './resolvers'
Then the resolvers would look as follows:
resolvers.ts
import { Resolvers } from './.mesh'
const resolvers: Resolvers = {
Mutation: {
async uploadFile(_, { upload }) {
const filename = upload.name
const arrayBuffer = await upload.arrayBuffer()
const buffer = Buffer.from(arrayBuffer)
// upload file to S3...
return { filename }
}
}
}
export default resolvers