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:
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:
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 @value
user @firebase(ref: "/users/$userId