Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!