Giter Club home page Giter Club logo

apollo-link-firebase-ng's Introduction

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$", 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 string

Additionally, 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.

apollo-link-firebase-ng's People

Contributors

dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

sidechat

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.