All Projects → swantzter → apollo-datasource-firestore

swantzter / apollo-datasource-firestore

Licence: MIT license
An Apollo DataSource for Firestore

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to apollo-datasource-firestore

cannercms
⚡️[NOT MAINTAINED] Content Management Framework creates custom CMS fast and easy. Support data sources such as Firebase/Firestore, GraphQL and Restful APIs.
Stars: ✭ 2,452 (+8657.14%)
Mutual labels:  apollo, firestore
Firestore Apollo Graphql
An example of a GraphQL setup with a Firebase Firestore backend. Uses Apollo Engine/Server 2.0 and deployed to Google App Engine.
Stars: ✭ 371 (+1225%)
Mutual labels:  apollo, firestore
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 (+8728.57%)
Mutual labels:  apollo, firestore
apollo-link-segment
Automatic analytics for Apollo Apps.
Stars: ✭ 18 (-35.71%)
Mutual labels:  apollo
barber-shop
Vue + Firebase (cloud functions, auth, firestore, hosting) reservations system
Stars: ✭ 47 (+67.86%)
Mutual labels:  firestore
airbnb-clone
Fullstack airbnb clone made with React/Ts/Nest
Stars: ✭ 37 (+32.14%)
Mutual labels:  apollo
FirestoreMovies
Simple Movie application showcasing use of Firestore document based database.
Stars: ✭ 28 (+0%)
Mutual labels:  firestore
dynamic-datasource-starter
springboot 动态切换数据的基本思想与实现方法
Stars: ✭ 12 (-57.14%)
Mutual labels:  datasource
typescript-graphql-postgres-boilerplate
Simple boilerplate integrated typescript, graphql, postgres and apollo server
Stars: ✭ 18 (-35.71%)
Mutual labels:  apollo
Firstsight
前后端分离,服务端渲染的个人博客,基于 Nodejs、 Vue、 Nuxt、Nestjs、PostgreSQL、Apollo
Stars: ✭ 19 (-32.14%)
Mutual labels:  apollo
ionic4-ngrx-firebase
A basic application for Ionic 4 with firebase & ngrx actions, reducers and effects
Stars: ✭ 17 (-39.29%)
Mutual labels:  firestore
apollo-local-query
Simpler server rendering with apollo-client 1.x, using a local GraphQL networkInterface
Stars: ✭ 66 (+135.71%)
Mutual labels:  apollo
react-apollo-client-testing-example
A React with Apollo Client application with a mocked GraphQL server and tested Query and Mutation components.
Stars: ✭ 17 (-39.29%)
Mutual labels:  apollo
gatsby-plugin-apollo-client
📡Inject a Shopify Apollo Client into the browser.
Stars: ✭ 20 (-28.57%)
Mutual labels:  apollo
graphql-blog-client
🚀 React Apollo client for a GraphQL blog.
Stars: ✭ 15 (-46.43%)
Mutual labels:  apollo
loopback-connector-firestore
Firebase Firestore connector for the LoopBack framework.
Stars: ✭ 32 (+14.29%)
Mutual labels:  firestore
mongodb-cakephp3
An Mongodb datasource for CakePHP 3.0
Stars: ✭ 29 (+3.57%)
Mutual labels:  datasource
les-chat
Real-time messenger with private, public & group chat. Made using PERN + GraphQL stack.
Stars: ✭ 48 (+71.43%)
Mutual labels:  apollo
likecoin-tx-poll
Firestore based service of polling eth status and resending tx
Stars: ✭ 13 (-53.57%)
Mutual labels:  firestore
firestore-jest-mock
Jest Helper library for mocking Cloud Firestore
Stars: ✭ 128 (+357.14%)
Mutual labels:  firestore

Apollo DataSource for Firestore

JavaScript Style Guide QA Publish to NPM and GCR codecov

This is a Firestore DataSource for Apollo GraphQL Servers. It was adapted from the CosmosDB DataSource

Usage

Use by creating a new class extending the FirestoreDataSource, with the desired document type. Use separate DataSources for each data type, and preferably different collections in Firestore too. Initialise the class by passing a collection reference created by the Firestore library.

export interface UserDoc {
  // a string id value is required for entities using this library.
  // It will be used for the firestore document ID but not stored in the document in firestore.
  readonly id: string
  readonly collection: 'users'
  name: string
  groupId: number
}

export interface PostsDoc {
  readonly id: string
  readonly collection: 'posts'
  title: string
}

export class UserDataSource extends FirestoreDataStore<UserDoc, ApolloContext> {}
export class PostsDataSource extends FirestoreDataStore<PostsDoc, ApolloContext> {}

const usersCollection: CollectionReference<UserDoc> = firestore.collection('users')
const postsCollection: CollectionReference<PostsDoc> = firestore.collection('posts')

const server = new ApolloServer({
  typeDefs,
  resolvers,
  dataSources: () => ({
    users: new UserDataSource(usersCollection),
    posts: new PostsDataSource(postsCollection)
  })
})

Custom queries

FirestoreDataSource has a findByQuery method that accepts a function taking the collection as its only argument, which you can then create a query based on. Can be used in resolvers or to create wrappers.

Example of derived class with custom query methods:

export class UserDataSource extends FirestoreDataStore<UserDoc, ApolloContext> {
  async findManyByGroupId (groupId: number) {
    return this.findManyByQuery(c => c.where('groupId', '==', groupId).limit(2))
  }

  async findOneByEmail (email: string) {
    return this.findManyByQuery(c => c.where('email', '==', email).limit(1))?.[0] ?? undefined
  }
}

Write Operations

This DataSource has some built-in mutations that can be used to create, update and delete documents.

await context.dataSources.users.createOne(userDoc)

await context.dataSources.users.updateOne(userDoc)

await context.dataSources.users.updateOnePartial(userId, { name: 'Bob' })

await context.dataSources.users.deleteOne(userId)

Batching

Batching is provided on all id-based queries by DataLoader.

Caching

Caching is available on an opt-in basis by passing a ttl option on queries.

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].