---
description:
  GraphQL Mesh enables easy file uploads with its built-in support for GraphQL Yoga server. Forward
  file uploads to sources with minimal configuration changes. Check out the example in the
  documentation for more details.
---

# File uploads

Thanks to its server based on [GraphQL Yoga](https://graphql-yoga.com), 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:

```mermaid
graph TD;
subgraph BB [" "]
E[ResizeImages API];
F[UploadFiles API];
end
Z[Mesh Gateway GraphQL API];
Z --> E;
Z --> F;
```

You will find the complete example in
[`examples/graphql-file-upload-example/.meshrc.yml`](https://github.com/ardatan/graphql-mesh/tree/master/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:

```yaml filename=".meshrc.yaml"
sources:
  # …
transforms:
  # …
additionalTypeDefs: |
  scalar File

  extend type Mutation {
    uploadFile(upload: File!): FileResult!
  }

additionalResolvers:
  - './resolvers'
```

Then the resolvers would look as follows:

```ts filename="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
```
