An example of a GraphQL setup with a Firebase Firestore backend. Uses Express and Express GraphQL.
git clone https://github.com/hkhamm/firestore-express-graphql.git
cd firestore-express-graphql
yarn install
- If you don't already have a Firebase project, add one in the Firebase console. The Add project dialog also gives you the option to add Firebase to an existing Google Cloud Platform project.
- Navigate to the Service Accounts tab in your project's settings page.
- Click the Generate New Private Key button at the bottom of the Firebase Admin SDK section of the Service Accounts tab.
After you click the button, a JSON file containing your service account's credentials will be downloaded. Rename this to service-account.json
and add it to the top level of the repo (e.g. /path/to/firebase-firestore-graphql/service-account.json
).
- From the Firebase console, create a new Firestore database.
- Create two collections, one of tweets and one of users. Follow these types:
interface User {
id: string
name: string
screenName: string
statusesCount: number
}
interface Tweet {
id: string
likes: number
text: string
userId: string
}
yarn start
If you navigate to /playground
you should see a GraphQL playground where you can query your API.
{
user(id: "1") {
name
tweets {
text
likes
}
}
}