I think I am just using this module wrong and that is the reason I am getting an error. According to the documentation I can pass an array of resolvers and schemas to the mergeSchemas
function from graphql-tools
. But I am getting this error:
Error: Apollo Server requires either an existing schema, modules or typeDefs
Here is the code:
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}`)
})
Merging Schemas
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?
})
Schema
type Query {
book(id: String!): Book
bookList: [Book]
}
type Book {
id: String
name: String
genre: String
}
Resolver
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` }
]
}
}
}