Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda