我认为我只是在错误地使用此模块,这就是我收到错误的原因。根据文档,我可以将解析器和模式数组从mergeSchemas
传递到graphql-tools
函数。但我收到此错误:
Error: Apollo Server requires either an existing schema, modules or typeDefs
代码如下:
app.js
import { ApolloServer } from 'apollo-server'
import schema from './modules'
const server = new ApolloServer({
schema
})
server.listen().then(({ url }) => {
console.log(` Server ready at ${url}`)
})
合并模式
import { mergeSchemas } from 'graphql-tools'
import bookSchema from './book/schema/book.gql'
import bookResolver from './book/resolvers/book'
export const schema = mergeSchemas({
schemas: [bookSchema],
resolvers: [bookResolver] // ==> Maybe I have to merge these before hand?
})
架构
type Query {
book(id: String!): Book
bookList: [Book]
}
type Book {
id: String
name: String
genre: String
}
解析器
export default {
Query: {
book: (parent, args, context, info) => {
console.log(parent, args, context, info)
return {
id: `1`,
name: `name`,
genre: `scary`
}
},
bookList: (parent, args, context, info) => {
console.log(parent, args, context, info)
return [
{ id: `1`, name: `name`, genre: `scary` },
{ id: `2`, name: `name`, genre: `scary` }
]
}
}
}
答案 0 :(得分:0)
严重错误:
需要从解构结构中导入模式对象:
MODE_PREEMPTIVE