Skip to content

shoNagai/firestore-dataloader

This branch is 1 commit ahead of main.

Folders and files

NameName
Last commit message
Last commit date
Mar 21, 2022
May 23, 2021
Jun 6, 2021
May 7, 2021
May 7, 2021
May 7, 2021
May 7, 2021
May 7, 2021
May 7, 2021
Jun 6, 2021
May 7, 2021
May 7, 2021
Feb 23, 2025
Jun 6, 2021
May 7, 2021
Feb 23, 2025

Repository files navigation

Firestore DataLoader

FirestoreDataLoader is a GraphQL DataLoader for Cloud Firestore.

Getting Started

First, install FirestoreDataLoader using npm or yarn.

npm install --save firestore-dataloader

or

yarn add firestore-dataloader

Usage

Initialize datasources by specifying a collection or query.

import { FirestoreDataLoader } from 'firestore-dataloader';

usersDataLoader: new FirestoreDataLoader<User>(db.collection(`users`)),

The second argument can optionally declare the DataLoader options. For more information on how to use the dataloader options, please refer to the dataloader repository.

Resolver can receive and use data loaders from context.

const Message: MessageResolvers = {
  async user(parent, _args, { dataSources: { usersDataLoader } }) {
    const user = await usersDataLoader.dataLoader.load(parent.id);
    if (!user) throw new ApolloError(`no user userId: ${parent.id}`);
    return userToGQL(user);
  },
};