I found a way of doing this by using grahpql-import which does exactly what I needed. See sample code below:
import { ApolloServer } from 'apollo-server-express'
import { importSchema } from 'graphql-import'
import Query from './resolvers/Query'
const typeDefs = importSchema('./src/schema.graphql')
const server = new ApolloServer({
typeDefs,
resolvers: {
Query
}
})
const app = express()
server.applyMiddleware({ app })
app.listen({ port: 4000 })
**
UPDATE: graphql-import v0.7+
**
importSchema
is now async and should be handled as a promise. Just wrap it in a async
function and simply await
it.
async function start() {
const typeDefs = await importSchema(".src/schema.graphql")
}