Last active
March 16, 2021 09:48
-
-
Save jthegedus/a193d7abb9df66aacc2782a58e214a86 to your computer and use it in GitHub Desktop.
GraphQL & Cloud Functions for Firebase example
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 {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}; |
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 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; |
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
const resolverFunctions = { | |
Query: { | |
hello: () => 'world' | |
} | |
}; | |
export default resolverFunctions; |
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
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