0.8.1 • Published 4 months ago

@graphql-ez/plugin-upload v0.8.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@graphql-ez/plugin-upload

Integration with GraphQL Upload

Compatibility

This plugin currently only supports Fastify, Express and Koa. If you really need this plugin in another integration, feel free to create an issue or a PR proposing the solution.

Usage

Make sure to have installed graphql-upload and @types/graphql-upload, since these are set as Peer Dependencies

This plugin integrates automatically with the GraphQL Codegen plugin

import { ezUpload } from '@graphql-ez/plugin-upload';

const ezApp = CreateApp({
  ez: {
    plugins: [
      // ...
      ezUpload({
        // UploadOptions
      }),
    ],
  },
  // ...
});
export interface UploadOptions {
  maxFieldSize?: number;
  maxFileSize?: number;
  maxFiles?: number;
}
// You also can use a helper exported from this plugin
// that automatically converts the graphql-upload ReadStream
// into a more developer-friendly "Buffer"
import { readStreamToBuffer } from '@graphql-ez/plugin-upload';

// ...
({
  // ...
  typeDefs: [
    // ...
    gql`
      type Mutation {
        uploadFileToBase64(file: Upload!): String!
      }
    `,
  ],
  resolvers: {
    // ...
    Mutation: {
      async uploadFileToBase64(_root, { file }, _ctx) {
        const fileBuffer = await readStreamToBuffer(file);

        return fileBuffer.toString('base64');
      },
    },
  },
});
0.8.1

4 months ago

0.8.0

1 year ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.0

2 years ago

0.6.2

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.2

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.1.2

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago