Shared code to run local apollo server next to firebase functions
const gql = require('graphql-tag'); | |
const { makeExecutableSchema } = require('graphql-tools'); | |
const books = [ | |
// ... | |
]; | |
const typeDefs = gql` | |
# ... | |
`; | |
const resolvers = { | |
Query: { | |
books: () => books, | |
}, | |
}; | |
module.exports = { | |
schema: makeExecutableSchema({ | |
typeDefs, | |
resolvers, | |
}), | |
// Bonus function, to remove stack trace on production | |
// https://www.apollographql.com/docs/apollo-server/features/errors | |
formatError: (error) => { | |
if (process.env.NODE_ENV === 'production') { | |
delete error.extensions.exception; | |
} | |
return error; | |
}, | |
} |
const { ApolloServer } = require('apollo-server-cloud-functions'); | |
const functions = require('firebase-functions'); | |
const config = require('./lib/config'); | |
const server = new ApolloServer(config); | |
const handler = server.createHandler({ | |
cors: { | |
origin: true, | |
credentials: true, | |
}, | |
}); | |
exports.handler = functions.https.onRequest(handler); |
const { ApolloServer } = require('apollo-server'); | |
const config = require('./config'); | |
const server = new ApolloServer(config); | |
// This `listen` method launches a web-server. Existing apps | |
// can utilize middleware options, which we'll discuss later. | |
server.listen().then(({ url }) => { | |
console.log(`🚀 Server ready at ${url}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment