2

I tried uploading a file to a graphql server that has graphql-tool. I have set up the request multipart specification and I use Altair graphql client to make a request to the graphql endpoint.

I get the error SyntaxError: Unexpected token - in JSON at position 0 I do not know what I am doing incorrectly. Please help me out.

Below is my code

const graphqlHTTP = require('express-graphql');
const { graphqlUploadExpress } = require('graphql-upload');

const { makeExecutableSchema } = require('@graphql-tools/schema');

const schema = makeExecutableSchema({
    typeDefs,
    resolvers
});
app.use("/graphql", 
graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 }),
graphqlHTTP((req, res) => ({
    schema,
    graphiql: true,
    context: {
        accessToken: req.header("accessToken"),
        authFunction: jwtAuthentication
    },
    tracing: true
})))

in my resolver, I included GraphQLUpload

module.exports = {
    Upload: GraphQLUpload,
    Query: {
      
    },
    Mutation: {
      ChangeBusinesslogo:  async (parent, { file }, context, info)=>  {
         // 
      },
    }
}

In my type definition, I have

    scalar Upload

    type File {
        id: ID!
        path: String!
        filename: String!
        mimetype: String!
        encoding: String!
    }

    type Mutation {
        ChangeBusinesslogo(file: Upload!): File
    }

I use altair graphql-client but I get this error

SyntaxError: Unexpected token - in JSON at position 0

I do not know what I am not doing correctly. Please help me out

joelostblom
  • 43,590
  • 17
  • 150
  • 159
  • 1
    The error message seems to be a response body is a text message from the server. You can use the Chrome dev tools network inspector to see the GraphQL response body – Rex Low May 18 '21 at 13:31

0 Answers0