Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

168
Vistas
Express GraphQL - upload files

I am creating my Express-GraphQL api where I can store everything in MongoDB. I am at the point where I have something like this:

Project Mongo model:

const { Schema, model } = require("mongoose");

const projectSchema = new Schema({
  name: {
    type: String,
    require: true,
  },
  offer: [{ type: String }],
});

module.exports = model("Project", projectSchema);

I deleted all fields except these 2. The field offer must be an array of files - for example you can have there 2-3 pdfs.

In my types I created Project type:

const Project = new GraphQLObjectType({
  name: "Project",
  fields: () => ({
    _id: { type: GraphQLNonNull(GraphQLString) },
    name: { type: GraphQLNonNull(GraphQLString) },
    offer: { type: GraphQLList(GraphQLString) }, 
  }),
});

I am wondering is there a way of creating a mutation that you can add/upload files in this offer field?

editProject: {
      type: Project,
      args: {
        projectId: { type: GraphQLNonNull(GraphQLString) },
        offer: { type: GraphQLList(GraphQLString) },  
      },

      async resolve(parentValue, args) {
        //some code here
      },
    },

If I have some mutation like that and how should I pass the files? If anybody have been doing something like this before I would be very thankful to share experience as I am:

  1. not sure if it is possible
  2. don't know how to pass the file in GraphQL mutation query
  3. don't know how exactly to store file in mongoDB (probably with GridFS)

Thanks a lot!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I have been working with graphql for almost 2 years now. And as you are facing this problem we also scratched our head about this quite a lot until we figured out that you can't really pass files in a mutation query but what you can do instead is upload your files from your frontend directly to a cloud service like AWS S3 and pass the object key in your mutation query to save it in your db. And to fetch it again from S3 you can use the same key. This way you are not handling your files in your backend and still keeping them safe with an efficient way to render or download at your frontend.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda