-
-
Save Emuentes/982e1761c04c94473d284fd6b23a0c83 to your computer and use it in GitHub Desktop.
Deploying a GraphQL Server with Firebase Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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