{"id":23613840,"url":"https://github.com/clement-muth/firebase-graphql-apollo-server","last_synced_at":"2026-04-10T15:09:46.459Z","repository":{"id":169854618,"uuid":"349395040","full_name":"Clement-Muth/firebase-graphql-apollo-server","owner":"Clement-Muth","description":"How to setup GraphQL using firebase functions. This example app demonstrate how to use firebase cloud functions with graphql query using apollo server express.","archived":false,"fork":false,"pushed_at":"2021-03-19T18:50:35.000Z","size":118,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-11T18:48:43.863Z","etag":null,"topics":["apollo-client","apollographql","express","firebase","firebase-functions","firebase-realtime-database","graphql","graphql-server","js","nodejs","nodejs-server"],"latest_commit_sha":null,"homepage":"https://azinove.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Clement-Muth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-19T11:10:10.000Z","updated_at":"2023-03-16T03:26:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"8ebaa049-e12e-4b3a-9c6b-39e03ee6a7bf","html_url":"https://github.com/Clement-Muth/firebase-graphql-apollo-server","commit_stats":null,"previous_names":["clement-muth/firebase-graphql-apollo-server"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Clement-Muth/firebase-graphql-apollo-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clement-Muth%2Ffirebase-graphql-apollo-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clement-Muth%2Ffirebase-graphql-apollo-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clement-Muth%2Ffirebase-graphql-apollo-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clement-Muth%2Ffirebase-graphql-apollo-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Clement-Muth","download_url":"https://codeload.github.com/Clement-Muth/firebase-graphql-apollo-server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clement-Muth%2Ffirebase-graphql-apollo-server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267913633,"owners_count":24164564,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apollo-client","apollographql","express","firebase","firebase-functions","firebase-realtime-database","graphql","graphql-server","js","nodejs","nodejs-server"],"created_at":"2024-12-27T17:29:09.384Z","updated_at":"2025-12-30T21:55:11.217Z","avatar_url":"https://github.com/Clement-Muth.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GraphQL Server Using Firebase Functions\r\n\r\n### Description\r\nHow to setup GraphQL using firebase functions.\r\nThis example app demonstrate how to use firebase cloud functions with graphql query using apollo server express.\r\n\r\n## What's [GraphQL](https://graphql.org/)\r\n\r\nGraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.\r\n\r\n## What's [Firebase Cloud Functions](https://firebase.google.com/docs/functions) ?\r\n\r\nCloud Functions for Firebase is a serverless framework that lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your JavaScript or TypeScript code is stored in Google's cloud and runs in a managed environment. There's no need to manage and scale your own servers.\r\n\r\n## What's [Apollo Client](https://www.apollographql.com/docs/react/) ?\r\n\r\nApollo Client is a comprehensive state management library for JavaScript that enables you to manage both local and remote data with GraphQL. Use it to fetch, cache, and modify application data, all while automatically updating your UI.\r\n\r\n## QuickStart\r\n\r\nNOTE: I recommend you to know basics of [firebase CLI](https://firebase.google.com/docs/cli) and setting up Node projects.\r\n\r\n### ◯ Step 1\r\n\r\nCreate a Firebase project !\r\n\r\nYou can get the firebase command by installing `firebase tools` globally\r\n\r\n```bash\r\n# npm\r\n$ sudo npm install -g firebase-tools\r\n\r\n# yarn\r\n$ sudo yarn add firebase-tools -W\r\n```\r\n\r\n```bash\r\n$ firebase init\r\n```\r\n\r\nThen choose functions and finish the configuration\r\n\r\n```bash\r\n◯ Functions: Configure and deploy Cloud Functions\r\n```\r\n\r\n### ◯ Step 2\r\n\r\n#### Install node modules \u0026 apollo server express dependencies\r\n\r\nGo to your functions directory\r\n\r\n```bash\r\n$ cd functions\r\n\r\n# npm\r\n$ npm install \u0026\u0026 npm install apollo-server-express express graphql\r\n\r\n# yarn\r\n$ yarn add apollo-server-express express graphql -W\r\n```\r\n\r\n### ◯ Step 3\r\n\r\nLet's set up firebase admin\r\n\r\n```js\r\nconst admin = require(\"firebase-admin\");\r\n\r\n// To generate a private key file for your service account:\r\n// 1. In the Firebase console, open Settings \u003e Service Accounts.\r\n// 2. Click Generate New Private Key, then confirm by clicking Generate Key.\r\n// 3. Add the JSON file in the `functions` directory\r\n\r\nconst serviceAccount = require('./serviceAccount.json');\r\n\r\nadmin.initializeApp({\r\n  credential: admin.credential.cert(serviceAccount),\r\n  databaseURL: 'https://\u003cDATABASE-NAME\u003e.firebasedatabase.app/',\r\n});\r\n```\r\n\r\n### ◯ Step 4\r\n\r\n#### Construct a gql schema\r\n\r\nimport gql from apollo-server-express and create a variable called typeDefs for your schema:\r\n\r\n```js\r\nconst { ApolloServer, gql } = require('apollo-server-express');\r\n\r\nconst typeDefs = gql`\r\n  type Cat {\r\n    name: String\r\n    lifespan: String\r\n  }\r\n\r\n  type Query {\r\n    cats: [Cat]\r\n  }\r\n`;\r\n```\r\n\r\n### ◯ Step 5\r\n\r\n#### Now the resolver\r\n\r\nIt will create the query and call your database\r\n\r\n```js\r\nconst resolvers = {\r\n  Query: {\r\n    cats: () =\u003e {\r\n      return admin\r\n        .database()\r\n        .ref('cats')\r\n        .once('value')\r\n        .then((snap) =\u003e snap.val())\r\n        .then((val) =\u003e Object.keys(val).map((key) =\u003e val[key]));\r\n    },\r\n  },\r\n};\r\n```\r\n\r\n### ◯ Step 6\r\n\r\n#### Connecting schema and resolvers to Apollo Server\r\n\r\n```js\r\nconst express = require('express');\r\n\r\nconst app = express();\r\nconst server = new ApolloServer({ typeDefs, resolvers });\r\n\r\nserver.applyMiddleware({ app, path: '/', cors: true });\r\n\r\n/* Change the region as you want */\r\nexports.graphql = functions.region('europe-west1').https.onRequest(app);\r\n```\r\n\r\n### ◯ Finally\r\n\r\n#### Let's check if it work locally\r\n\r\n```bash\r\nfirebase serve\r\n```\r\n\r\nMaybe you'll have to specify the right url\r\n\r\n![screencapture-localhost-5000-gql-test-123-europe-west1-graphql-2021-03-19-14_03_29](https://user-images.githubusercontent.com/58605856/111784674-f70cb880-88bb-11eb-8c2e-d1565a98f0cb.png)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclement-muth%2Ffirebase-graphql-apollo-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclement-muth%2Ffirebase-graphql-apollo-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclement-muth%2Ffirebase-graphql-apollo-server/lists"}