All Projects → Canner → Apollo Link Firebase

Canner / Apollo Link Firebase

Licence: mit
🔥 🔗 apollo-link-firebase provides you a simple way to use Firebase with graphQL.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Apollo Link Firebase

Apollo Errors
Machine-readable custom errors for Apollostack's GraphQL server
Stars: ✭ 405 (-2.41%)
Mutual labels:  graphql, apollo-client
Kit
ReactQL starter kit (use the CLI)
Stars: ✭ 232 (-44.1%)
Mutual labels:  graphql, apollo-client
Prisma Auth0 Example
Boilerplate Prisma Startup
Stars: ✭ 184 (-55.66%)
Mutual labels:  graphql, apollo-client
Apollo Cache Redux
Redux cache for Apollo Client 2.0. This project is no longer maintained.
Stars: ✭ 179 (-56.87%)
Mutual labels:  graphql, apollo-client
Apollo Storybook Decorator
Wrap your storybook environment with Apollo Client, provide mocks for isolated UI testing with GraphQL
Stars: ✭ 333 (-19.76%)
Mutual labels:  graphql, apollo-client
Gqlify
[NOT MAINTAINED]An API integration framework using GraphQL
Stars: ✭ 182 (-56.14%)
Mutual labels:  graphql, firebase
Canner
⚡️[NOT MAINTAINED] Content Management Framework creates custom CMS fast and easy. Support data sources such as Firebase/Firestore, GraphQL and Restful APIs.
Stars: ✭ 2,472 (+495.66%)
Mutual labels:  graphql, firebase
Reactql
Universal React+GraphQL starter kit: React 16, Apollo 2, MobX, Emotion, Webpack 4, GraphQL Code Generator, React Router 4, PostCSS, SSR
Stars: ✭ 1,833 (+341.69%)
Mutual labels:  graphql, apollo-client
Next Shopify Storefront
🛍 A real-world Shopping Cart built with TypeScript, NextJS, React, Redux, Apollo Client, Shopify Storefront GraphQL API, ... and Material UI.
Stars: ✭ 317 (-23.61%)
Mutual labels:  graphql, apollo-client
Apollo Client
🚀  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
Stars: ✭ 17,070 (+4013.25%)
Mutual labels:  graphql, apollo-client
Space Cloud
Open source Firebase + Heroku to develop, scale and secure serverless apps on Kubernetes
Stars: ✭ 3,323 (+700.72%)
Mutual labels:  graphql, firebase
Graphcool Templates
📗 Collection of Graphcool Templates
Stars: ✭ 354 (-14.7%)
Mutual labels:  graphql, firebase
Workshops
Workshops organized to introduce students to security, AI, AR/VR, hardware and software
Stars: ✭ 162 (-60.96%)
Mutual labels:  graphql, firebase
Persistgraphql
A build tool for GraphQL projects.
Stars: ✭ 409 (-1.45%)
Mutual labels:  graphql, apollo-client
Next Graphql Blog
🖊 A Blog including a server and a client. Server is built with Node, Express & a customized GraphQL-yoga server. Client is built with React, Next js & Apollo client.
Stars: ✭ 152 (-63.37%)
Mutual labels:  graphql, apollo-client
Apollo Offline
An offline toolkit for the Apollo client
Stars: ✭ 186 (-55.18%)
Mutual labels:  graphql, apollo-client
Graphql Directive
Use custom directives in your GraphQL schema and queries 🎩
Stars: ✭ 142 (-65.78%)
Mutual labels:  graphql, apollo-client
Typescript Expo Apollo Boilerplate
Clean boilerplate for TypeScript + Expo (React Native) + React Apollo (GraphQL)
Stars: ✭ 144 (-65.3%)
Mutual labels:  graphql, apollo-client
Ember Apollo Client
🚀 An ember-cli addon for Apollo Client and GraphQL
Stars: ✭ 257 (-38.07%)
Mutual labels:  graphql, apollo-client
Absinthe
The GraphQL toolkit for Elixir
Stars: ✭ 3,805 (+816.87%)
Mutual labels:  graphql, apollo-client

npm version CircleCI gitter

Apollo-link-firebase

apollo-link-firebase provides you a simple way to query Firebase in graphQL with Apollo-client without building a graphQL server

Currently, we support features below:

  1. Query: All sorting and filtering methods on document are supported.
  2. Mutation: deal with set, update, remove methods with graphQL mutation.
  3. Realtime Subscription: Listen to your Firebase events using graphQL Subscription.
  4. Data Join: Retrieve your data from different paths using one graphQL.

Contents

Installation

yarn add apollo-link-firebase

Quickstart

// rtdb stands for realtime database
import {createRtdbLink} from 'apollo-link-firebase';
import * as firebase from 'firebase';

// initialize firebase
firebase.initializeApp({
  // configs
});

// create Realtime Database link
const rtdbLink = createRtdbLink({
  database: firebase.database()
});

const client = new ApolloClient({
  link: rtdbLink,
  cache: new InMemoryCache(),
});

// A simple query to retrieve data from 
// firebase.database().ref("/profile/me")
// @rtdbQuery stands for Realtime Database Query
const query = gql`
  query myProfile {
    me @rtdbQuery(ref: "/profile/me") {
      name
    }
  }
`;

// Invoke the query and log the person's name
client.query({ query }).then(response => {
  console.log(response.data.name);
});

Retrieve Object Data

Return with __typename

In Apollo client, InMemoryCache use __typename and id to save your data in store.

Using @key directive, you can speficy which field you want to return with the key of snapshot

const query = gql`
  query myProfile {
    me @rtdbQuery(ref: "/profile/me", type: "Profile") {
      id @key
      name
    }
  }
`;

Response

{
  __typename: "Profile",
  id: "me",
  name: "wwwy3y3"
}

Work with Lists of Data

For example, your data in Firebase could be like

{
  users: {
    id1: {
      name: "alovelace",
      birth: 1815
    },
    id2: {
      name: "ghopper",
      birth: 1906
    }
  }
}

Basic Query

We can query all users, and use @array directive to parse data to array

const query = gql`
  query getUsers {
    users @rtdbQuery(ref: "/users", type: "Users") @array {
      id @key
      name
    }
  }
`;

Response

[{
  __typename: "Users",
  id: "id1",
  name: "alovelace",
  birth: 1815
}, {
  __typename: "Users",
  id: "id2",
  name: "ghopper",
  birth: 1906
}]

Advance Query

In firebase client js sdk, We can get data by using sorting and filtering API

We provide corresponding API in @rtdbQuery directive arguments. In the following example, we query lists of data using orderByChild("birth") and limitToFirst(1)

const query = gql`
  query getUsers {
    users @rtdbQuery(ref: "/users", orderByChild: "birth", limitToFirst: 1, type: "Users") {
      name
    }
  }
`;

Response

[{
  __typename: "Users",
  id: "id1",
  name: "alovelace",
  birth: 1815
}]

rtdbQuery Directive Arguments

  • ref: string
  • orderByChild: string
  • orderByKey: boolean. e,g orderByKey: true
  • orderByValue: boolean
  • startAt: any
  • endAt: any
  • equalTo: any
  • limitToFirst: number
  • limitToLast: number

More Examples

Mutation

We only take payload from input key from the recommendations in this article

const mutation = gql`
  fragment Input on firebase {
    string: String
    number: Number
  }

  mutation($ref: string, $input: Input!) {
    updateArticle(input: $input) @rtdbUpdate(ref: $ref, type: "Article") {
      id @key
      string
      number
    }
  }
`;

We support four directives for mutation

  • @rtdbUpdate: Firebase update
  • @rtdbSet: Firebase set
  • @rtdbRemove: Firebase remove
  • @rtdbPush: Push new element under ref, sugar api for firebase push and set

Examples

@rtdbRemove

const mutation = gql`
  mutation($ref: string) {
    remove @rtdbRemove(ref: $ref)
  }
`;

@rtdbPush and @pushKey

const mutation = gql`
  fragment ProfileInput on firebase {
    string: String
    number: Number
  }

  mutation($ref: string, $input: ProfileInput!) {
    pushdata(input: $input) @rtdbPush(ref: $ref) {
      id @pushKey
      string
      number
    }
  }
`;

// variables
const variables = {
  ref: "/users",
  input: {
    string: "string",
    number: 1
  }
}

// response
{
  id: "-KjCIvxsKueb3Hf2LIOp",
  string: "string",
  number: 1
}

Subscription

We support four events in Firebase, more on Firebase document

You can use all the query api supported in @rtdbQuery, more advanced query examples in wiki

Usage

const subQuery = gql`
  subscription {
    newComment @rtdbSub(ref: "/comments", event: "value") {
      id @key
      content
    }
  }
`;

Directives

  • value: @rtdbSub(ref: string, event: "value")
  • child_added: @rtdbSub(ref: string, event: "child_added")
  • child_changed: @rtdbSub(ref: string, event: "child_changed")
  • child_removed: @rtdbSub(ref: string, event: "child_removed")

Example

Simple Todo React Application

Here's a simple React + apollo-link-firebase todo app

Roadmap

  • support firebase transaction
  • support firestore
  • support authenticate mutation
  • support storage mutation

Contribution

Contributions are welcome and extremely helpful 🙌

Feel free to join our gitter channel to discuss with us!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].