2

我尝试将文件上传到具有 graphql-tool 的 graphql 服务器。我已经设置了请求多部分规范,并使用 Altair graphql 客户端向 graphql 端点发出请求。

我收到错误SyntaxError: Unexpected token - in JSON at position 0 ,我不知道我做错了什么。请帮帮我。

下面是我的代码

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
})))

在我的解析器中,我包括GraphQLUpload

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

在我的类型定义中,我有

    scalar Upload

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

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

我使用 altair graphql-client 但我收到此错误

SyntaxError: Unexpected token - in JSON at position 0

我不知道我做错了什么。请帮帮我

4

0 回答 0