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