我正在尝试使用 apollo 进行模式拼接,但每次使用 makeExecutableSchema 时都会出现错误。错误如下:
../node_modules/graphql-tools/dist/generate/concatenateTypeDefs.js:9:
-> if (typeDef.kind !== undefined)
TypeError: Cannot read property 'kind' of undefined
即使只是复制 Apollo 上的基本示例 website,我也重现了该问题。
const { ApolloServer, gql, makeExecutableSchema } = require("apollo-server");
const { addMockFunctionsToSchema, mergeSchemas } = require("graphql-tools");
const chirpSchema = makeExecutableSchema({
typeDefs: `
type Chirp {
id: ID!
text: String
authorId: ID!
}
type Query {
chirpById(id: ID!): Chirp
chirpsByAuthorId(authorId: ID!): [Chirp]
}
`
});
addMockFunctionsToSchema({ schema: chirpSchema });
const authorSchema = makeExecutableSchema({
typeDefs: `
type User {
id: ID!
email: String
}
type Query {
userById(id: ID!): User
}
`
});
addMockFunctionsToSchema({ schema: authorSchema });
const schema = mergeSchemas({
schemas: [chirpSchema, authorSchema]
});
const server = new ApolloServer(schema);
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
我做错了什么?但是我尝试使用 makeExecutableSchema 时总是遇到相同的错误。
最佳答案
据我所知,您正在使用 [email protected] 在这个版本中 ApolloServer构造函数接收一个选项参数
您应该传递new ApolloServer({ schema: schema })
而不是new ApolloServer(schema)
我尝试了你给出的例子,它成功了:)
关于javascript - Apollo makeExecutableSchema 抛出错误 "Cannot read property ' 种“未定义”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51173778/