Apollo-server: Won't run on Firebase Functions

Created on 19 Nov 2018  路  5Comments  路  Source: apollographql/apollo-server

Attempting to get minimal example running on Firebase Cloud Functions and ran into what appear to be compile time errors.

To reproduce:

1) initialize firebase project with functions, typescript, and TSLint options
2) paste the below in index.ts
3) run this in shell npm run build && firebase serve

import * as functions from "firebase-functions";
import * as express from "express";
import { ApolloServer, gql } from "apollo-server-express";

const typeDefs = gql`
  type Query {
    hello: String!
  }
`;

const resolvers = {
  Query: {
    hello: () => "World!"
  }
};

const server = new ApolloServer({ typeDefs, resolvers });

const app2 = express();
server.applyMiddleware({ app: app2 });

export const api2 = functions.https.onRequest(app2);

Result

> functions@ build /Users/lukepighetti/code/purse/firebase/functions
> tsc

node_modules/apollo-server-core/dist/ApolloServer.d.ts(33,56): error TS1005: '>' expected.
node_modules/apollo-server-core/dist/ApolloServer.d.ts(33,63): error TS1003: Identifier expected.
node_modules/apollo-server-core/dist/ApolloServer.d.ts(33,92): error TS1144: '{' or ';' expected.
node_modules/apollo-server-core/dist/ApolloServer.d.ts(33,108): error TS1005: ';' expected.
node_modules/apollo-server-core/dist/ApolloServer.d.ts(33,109): error TS1109: Expression expected.
node_modules/apollo-server-core/dist/ApolloServer.d.ts(34,1): error TS1128: Declaration or statement expected.

My tsconfig.json (changing this to a working example with apollo-server didn't improve things)

{
  "compilerOptions": {
    "lib": ["es6"],
    "module": "commonjs",
    "noImplicitReturns": true,
    "outDir": "lib",
    "sourceMap": true,
    "target": "es6"
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

Most helpful comment

I had some troubles running apolloserver on firebase cloud functions, but after a couple tries, apollo-server-cloud-functions worked just fine. I think this issue can be closed now.

For anyone still interested, I published an article about my setup

All 5 comments

Got it to work by upgrading to typescript 3.1.6 from 2.x.x, and using this tsconfig.json

{
  "compilerOptions": {
    "lib": ["es6", "esnext.asynciterable"],
    "module": "commonjs",
    "noImplicitReturns": true,
    "outDir": "lib",
    "sourceMap": true,
    "allowSyntheticDefaultImports": true,
    "target": "es6"
  },
  "compileOnSave": true,
  "include": ["src"]
}

Any reason you're not using apollo-server-cloud-functions?

Firebase functions are basically just cloud functions with a nicer developer experience so the package will be working just fine!

To be honest, I didn't know that there was a package for cloud functions already. I'll have to dig in another day. Cheers!

I had some troubles running apolloserver on firebase cloud functions, but after a couple tries, apollo-server-cloud-functions worked just fine. I think this issue can be closed now.

For anyone still interested, I published an article about my setup

Closing this since it appears to be resolved 鉁岋笍

Was this page helpful?
0 / 5 - 0 ratings