Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/steelbrain/apollo-link-firebase-ng
Query/Subscribe to Firebase Realtime DB with GraphQL/Apollo.
https://github.com/steelbrain/apollo-link-firebase-ng
Last synced: 10 days ago
JSON representation
Query/Subscribe to Firebase Realtime DB with GraphQL/Apollo.
- Host: GitHub
- URL: https://github.com/steelbrain/apollo-link-firebase-ng
- Owner: steelbrain
- Created: 2020-03-20T07:53:07.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T02:41:55.000Z (almost 2 years ago)
- Last Synced: 2024-03-04T09:36:02.198Z (8 months ago)
- Language: TypeScript
- Homepage:
- Size: 1.12 MB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Apollo Link Firebase
Query/Subscribe to Firebase Realtime DB with GraphQL/Apollo.
### Installation
```
yarn add apollo-link-firebase-ng
# OR
npm install apollo-link-firebase-ng
```### Setup
Just add the `apollo-link-firebase-ng` package as Link in your Apollo link chain. Here's a minimal example
of the setup:```js
const client = new ApolloClient({
link: createFirebaseLink({
database: firebase.database(),
}),
cache: new InMemoryCache({
addTypename: true,
}),
})
```This package can be used in conjuction with other link packages, it only intercepts the queries involving `@firebase`. Please make sure this package appears above the HTTP link package in the chain. Otherwise all requests will go through that package.
### Usage
This package supports Queries and Subscriptions on Firebase resources, eg:
```js
const query = gql`
fragment Homepage_User on User {
id
username
lastActive
}
query {
users @firebase(ref: "/users/", type: "User") {
id @key
...Homepage_User
}
activeUsers @firebase(ref: "/activeUsers", type: "ActiveUser", limitToFirst: 30) {
id @key @export(as: "userId")
status @valueuser @firebase(ref: "/users/$userId$", type: "User") {
id @import(from: "userId")
...Homepage_User
}
}
}
`
```### API
Supported `@firebase` directive arguments:
- `type` - translated to `__typename` for Apollo cache
- `ref` - string
- `orderByChild` string
- `orderByKey` boolean
- `orderByValue` boolean
- `limitToFirst` number
- `limitToLast` number
- `startAt` string
- `endAt` string
- `equalTo` stringAdditionally, you can use the following directives:
- `@array` to mark a Firebase value as array. This can turn associative objects into arrays
- `@key` to assign associative object keys to a field value
- `@value` to get raw access to Firebase value
- `@export(as: "fieldName")` to export the value of a field, to be used as variable in another firebase directive
- `@import(from: "fieldName")` to import the value of a sibling or parent exporter of same name
- `@defer` to make parent field resolver despite lack of value on firebase subquery. Be careful with using this on deep arrays, as it'll re-render for each individual item received.Note that the objects received are to be treated as references, this is to save CPU/Memory when possible. Consumers can choose to deep clone the response when necessary.
### LICENSE
The contents of this package/repository are licensed under the terms of MIT License. See the LICENSE file for more info.