Skip to content

Instantly share code, notes, and snippets.

@jthegedus
Last active March 16, 2021 09:48
Show Gist options
  • Save jthegedus/a193d7abb9df66aacc2782a58e214a86 to your computer and use it in GitHub Desktop.
Save jthegedus/a193d7abb9df66aacc2782a58e214a86 to your computer and use it in GitHub Desktop.
GraphQL & Cloud Functions for Firebase example
import {https} from 'firebase-functions';
import gqlServer from './graphql/server';
const server = gqlServer();
// Graphql api
// https://us-central1-<project-name>.cloudfunctions.net/api/
const api = https.onRequest(server);
export {api};
import express from 'express';
import {ApolloServer} from 'apollo-server-express';
import schema from './schema';
import resolvers from './resolvers';
function gqlServer() {
const app = express();
const apolloServer = new ApolloServer({
typeDefs: schema,
resolvers,
// Enable graphiql gui
introspection: true,
playground: true
});
apolloServer.applyMiddleware({app, path: '/', cors: true});
return app;
}
export default gqlServer;
const resolverFunctions = {
Query: {
hello: () => 'world'
}
};
export default resolverFunctions;
const {gql} = require('apollo-server-express');
const schema = gql`
type Query {
"A simple type for getting started!"
hello: String
}
`;
export default schema;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment