Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/steelbrain/apollo-link-firestore
Query Google Firebase Firestore with GraphQL in Apollo
https://github.com/steelbrain/apollo-link-firestore
apollo firebase firestore gql graphql
Last synced: 2 months ago
JSON representation
Query Google Firebase Firestore with GraphQL in Apollo
- Host: GitHub
- URL: https://github.com/steelbrain/apollo-link-firestore
- Owner: steelbrain
- License: mit
- Created: 2021-03-03T08:55:50.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-05-25T00:18:02.000Z (over 2 years ago)
- Last Synced: 2024-10-23T08:51:46.323Z (3 months ago)
- Topics: apollo, firebase, firestore, gql, graphql
- Language: TypeScript
- Homepage:
- Size: 149 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Apollo Link Firestore
Query Google Firebase Firestore with GraphQL in Apollo. Allows doing joins in Firebase via GQL syntax.
#### Installation
```
yarn add @apollo/client @steelbrain/apollo-link-firestore
# or
npm install @apollo/client @steelbrain/apollo-link-firestore
```To use this Apollo Link adapter, modify your Apollo client creation like so
```js
import { ApolloClient, InMemoryCache, from } from '@apollo/client'
import createFirestoreLink from '@steelbrain/apollo-link-firestore'const client = new ApolloClient({
link: from([
createFirestoreLink({
firestore: firebase.firestore(),
}),
]),
cache: new InMemoryCache(),
})
```#### Usage
To activate Firestore link on a GraphQL node, simply add the @firestore directive with the relevant arguments.
This package supports both `Query` and `Subscription` in GQL.Here is an example query that showcases the API
```js
const query = gql`
subscription Test {
conversation @firestore(collection: "conversations", where: [["$id", "==", "NMI01qpXobQwd4HtKhgU"]]) {
title
}
conversations2 @firestore(collection: "conversations", where: [["id", ">", 0]]) {
title
}
conversations @firestore(collection: "conversations") {
title
type
fancyMembers {
user: id @firestore(collection: "users") {
id
display_name
z
}
}
members @firestore(collection: "users") {
id
user: id @firestore(collection: "users") {
id
display_name
}
display_name
y
}
messages @firestore(subcollection: "messages", limit: 20, order: ["id", "desc"]) {
id
user: userId @firestore(collection: "users") {
id
display_name
x
}
}
}
}
`,
```Here's the output of the query (outdated)
```json
{
"conversations2": [],
"conversations": {
"__type": "collection",
"NMI01qpXobQwd4HtKhgU": {
"fancyMessages": [{"id": 1}, {"id": 2}],
"members": [1,2],
"title": "Joe & Jane",
"type": "group",
"messages": {
"__type": "collection",
"uFBuo6CJu1knYqlzjzWl": {
"userId": 3
},
"3PUKrbtpEGe14cmanKVy": {
"userId": 2
}
}
}
},
"users": {
"2": {
"display_name": "John Doe"
}
}
}
```Here is the database state used
```json
[
{
"title": "Drew & Anees",
"type": "group",
"__typename": "conversations",
"members": [
{
"id": "2",
"display_name": "Anees B",
"y": null,
"__typename": "users",
"user": {
"id": "2",
"display_name": "Anees B",
"__typename": "users"
}
},
null
],
"fancyMembers": [
{
"__typename": null,
"user": {
"id": "2",
"display_name": "Anees B",
"z": null,
"__typename": "users"
}
},
{
"__typename": null,
"user": null
}
],
"messages": [
{
"id": "3PUKrbtpEGe14cmanKVy",
"__typename": "messages",
"user": {
"id": "2",
"display_name": "Anees B",
"x": null,
"__typename": "users"
}
},
{
"id": "uFBuo6CJu1knYqlzjzWl",
"__typename": "messages",
"user": null
}
]
}
]
```#### License
This project is licensed under the terms of MIT License. See the License file for more info.