Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jthegedus/7e85432a34bcd78821349800284a9818 to your computer and use it in GitHub Desktop.
Save jthegedus/7e85432a34bcd78821349800284a9818 to your computer and use it in GitHub Desktop.
Cloud Functions for Firebase - GraphQL Server - /functionsES6/graphql/server.js
import bodyParser from "body-parser"
import express from "express"
import { graphqlExpress, graphiqlExpress } from "graphql-server-express"
import schema from "./data/schema"
import { printSchema } from "graphql/utilities/schemaPrinter"
const setupGraphQLServer = () => {
// setup server
const graphQLServer = express()
// /api/graphql
graphQLServer.use(
"/graphql",
bodyParser.json(),
graphqlExpress({ schema, context: {} })
)
// /api/graphiql
graphQLServer.use(
"/graphiql",
graphiqlExpress({ endpointURL: "/api/graphql" })
)
// /api/schema
graphQLServer.use("/schema", (req, res) => {
res.set("Content-Type", "text/plain")
res.send(printSchema(schema))
})
return graphQLServer
}
export default setupGraphQLServer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment