I’m a newbie to Apollo/Server and I’m trying to get the simplest install as possible working on Firebase Functions. Has anyone achieved this or is it even possible? I’m going around in circles.
Here is what I’m currently failing to deploy:
const ApolloServer = require("@apollo/server");
const expressMiddleware = require("@apollo/server/express4");
const express = require("express");
const http = require("http");
const cors = require("cors");
const bodyParser = require("body-parser");
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
// The GraphQL schema
const typeDefs = `#graphql
type Query {
hello: String
}
`;
// A map of functions which return data for the schema.
const resolvers = {
Query: {
hello: () => "world",
},
};
const app = express();
const httpServer = http.createServer(app);
// Set up Apollo Server
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [
{
async serverWillStart() {
return {
async drainServer() {
await httpServer.drain();
},
};
},
},],
});
server.start().then(() =>{
app.use(
cors(),
bodyParser.json(),
expressMiddleware(server),
);
});
exports.gql = functions
.region("europe-west3")
.https.onRequest(app);
exports.test = functions
.region("europe-west3")
.https.onRequest( (req, res) => {
res.send("Hello");
});
As you can see it’s simple and a modification of the example given in the docs.