Last active
April 1, 2018 08:43
-
-
Save jthegedus/7e85432a34bcd78821349800284a9818 to your computer and use it in GitHub Desktop.
Cloud Functions for Firebase - GraphQL Server - /functionsES6/graphql/server.js
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
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
https://gist.github.com/jthegedus/7e85432a34bcd78821349800284a9818#file-cf4f-graphql-firebasefunctions-graphql-server-js-L3 should be
apollo-server-express