@graphql-ez/plugin-upload
TypeScript icon, indicating that this package has built-in type declarations

0.8.1 • Public • Published

@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');
      },
    },
  },
});

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @graphql-ez/plugin-upload

    Weekly Downloads

    23

    Version

    0.8.1

    License

    MIT

    Unpacked Size

    11.2 kB

    Total Files

    6

    Last publish

    Collaborators

    • pablosz