Skip to content

Instantly share code, notes, and snippets.

@brygrill
Last active August 4, 2020 14:12
Show Gist options
  • Save brygrill/c473d48fa7ad13ffa84f1528e4d90690 to your computer and use it in GitHub Desktop.
Save brygrill/c473d48fa7ad13ffa84f1528e4d90690 to your computer and use it in GitHub Desktop.
Deploying a GraphQL Server with Firebase Functions
// sample graphql server deployed with firebase functions
// minimal server setup
// via http://graphql.org/graphql-js/running-an-express-graphql-server/
const functions = require('firebase-functions');
const express = require('express');
const graphqlHTTP = require('express-graphql');
const { buildSchema } = require('graphql');
// Init express
const app = express();
// Construct a schema, using GraphQL schema language
const schema = buildSchema(`
type Query {
hello: String
}
`);
// The root provides a resolver function for each API endpoint
var root = {
hello: () => {
return 'Hello world!';
},
};
app.use('/', graphqlHTTP({
schema: schema,
rootValue: root,
graphiql: true,
}));
exports.graphql = functions.https.onRequest(app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment