Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

400 Bad Request while uploading file in Altair using graphql and apollo

enter image description here

400 Bad Request while uploading file in Altair using graphql and apollo here is my code when I send a request to the server only in uploading file I get this kind of error: is there any way I could upload a file without getting this error

const {  gql } = require('apollo-server-express');

  
export default gql`
   scalar Upload
   type User{
    id: Int! 
    firstName: String!
    lastName:  String!
    userName:  String! 
    email:     String! 
    createdAt: String!
    updatedAt: String!
    bio:       String
    avatar:    String

   }
   type loginResult{
    ok:    Boolean!
    token: String
    Error: String

   }
   type editProfileResult{
    ok: Boolean!
    Error: String
   }
   type Mutation{
    creatUser(
        firstName: String!
        lastName:  String!
        userName:  String! 
        email:     String! 
        password:  String!
    
    ):User
    logIn(userName: String!, password: String!):loginResult!
    editProfile(firstName: String
        lastName:  String
        userName:  String
        email:     String 
        password:  String
        bio:        String
        avatar:    Upload ):editProfileResult!
   }
like image 651
amghare Avatar asked Dec 21 '25 19:12

amghare


2 Answers

I had the same issue and figured that I should use the graphqlUploadExpress from graphql-upload in my node.js server.

import { graphqlUploadExpress } from 'graphql-upload/graphqlUploadExpress.mjs';

app.use(graphqlUploadExpress());
like image 51
SakisTsalk Avatar answered Dec 24 '25 05:12

SakisTsalk


Using below worked for me!

import { graphqlUploadExpress } from 'graphql-upload/graphqlUploadExpress.mjs';

app.use(graphqlUploadExpress());
like image 35
Rogier de Ruijter Avatar answered Dec 24 '25 05:12

Rogier de Ruijter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!