Graphql 阿波罗服务器2.0。“类型”;上传“;在文档中找不到

Graphql 阿波罗服务器2.0。“类型”;上传“;在文档中找不到,graphql,apollo,apollo-server,Graphql,Apollo,Apollo Server,如何复制: server.js const { ApolloServer, makeExecutableSchema, gql } = require('apollo-server'); const typeDefs = gql` type Mutation { uploadAvatar(upload: Upload!): String! } `; const resolvers = { Mutation: { uploadAvatar(root, args,

如何复制:

server.js

const { ApolloServer, makeExecutableSchema, gql } = require('apollo-server');

const typeDefs = gql`
type Mutation {
    uploadAvatar(upload: Upload!): String!
}
`;
const resolvers = {
    Mutation: {
        uploadAvatar(root, args, context, info) {
            return 'test';
        }
    }
  };

const schema = makeExecutableSchema({ typeDefs, resolvers });

const server = new ApolloServer({
  schema,
});

server.listen().then(({ url }) => {
  console.log(`There are a couple of ways I've fixed this, in the example on the apollo docs:

https://www.apollographql.com/docs/guides/file-uploads.html

you can see he doesn't use
makeExecutableSchema
but passed the resolvers and schema to the apollo server this stopped the error:

Type "Upload" not found in document.

If you want to use
makeExecutableSchema
then import the scalar

const typeDefs = gql`
  scalar Upload

  type Mutation {
    uploadAvatar(upload: Upload!): String!
  }
  type Query {
    ping: String
  }
`;
const{apollo-server,makeExecutableSchema,gql}=require('apollo-server');
常量typeDefs=gql`
类型突变{
上传头像(上传:上传!):字符串!
}
`;
常量解析程序={
突变:{
上传头像(根、参数、上下文、信息){
返回“测试”;
}
}
};
const schema=makeExecutableSchema({typeDefs,resolvers});
const server=新服务器({
模式,
});
server.listen().then({url})=>{

log(`在apollo文档的示例中,我有几种方法解决了这个问题:

您可以看到,他没有使用
makeExecutableSchema
,而是将解析程序和架构传递给apollo服务器,从而停止了错误:

在文档中找不到类型“Upload”

如果要使用
makeExecutableSchema
,请导入标量

如果您查看at博客文章的一些示例源代码,您可以看到他使用了标量

它没有被自动添加的原因是

标量上传 Apollo Server自动添加到架构的上载类型解析包含以下内容的对象:

  • 溪流
  • 文件名
  • 模版
  • 编码
更新:Apollo更清楚地表明,当您使用makeExecutableSchema时,您需要定义标量以使其工作

在使用makeExecutableSchema手动设置模式并使用模式参数传递给ApolloServer构造函数的情况下,将上载标量添加到类型定义并上载到解析器


它似乎应该正常工作:``` Apollo Server 2.0会自动将上载标量添加到架构中,因此架构中任何现有的标量上载声明都应该删除```