Git Product home page Git Product logo

graphql-firestore-subscriptions's Introduction

🀘🏽 Hello Stranger!

I'm a 36 years old Software Engineer from Ostermunich, Bavaria. My journey began when I was 14 years old. In a college in the middle of the mountains I decided to focus on building websites. The internet just turned 10 years old, almost nothing was available to kickstart a kid in programming. With a few printed sheets in my backpack I managed to kick things off. Since then, the passion never faded. At the moment I am working for Bayerischer Rundfunk (one of the biggest german broadcasters) and Kerngedanke (a social media content management system).

graphql-firestore-subscriptions's People

Contributors

dependabot[bot] avatar ethanbonin avatar jonathanweiss avatar m19c avatar pixelmord avatar s-h-a-d-o-w avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

graphql-firestore-subscriptions's Issues

Further improve typings

Some types in graphql-firestore-subscriptions package are not optimally designed.
In addition, various Objects and Functions are also not clearly defined.

Example with subscriptions per user?

Hi, I'm not sure the proper way to do this, but I was looking at your example and wondering how to subscribe users to only new comments that are directed at them.

Do I somehow pass in the userId with the options?

const userHandler: UserHandler = (broadcast, { userId } = { userId: undefined }) => {
  return firebase
    .firestore()
    .collection(`users/${userId}/comments`)
    .onSnapshot((snapshot) => {
      snapshot
        .docChanges()
        .filter((change) => change.type === 'added')
        .map(({ doc }) => broadcast({ id: doc.id, ...doc.data() }));
    });
};
export const pubsub = new PubSub();
pubsub.registerHandler(NEW_COMMENT, (broadcast, options) => userHandler(broadcast, options));

I was also looking at using withFilter. Not sure if this is the intended usage:

commentAdded: async (_, { userId }, context) => {
      return withFilter(
        () => pubsub.asyncIterator(NEW_COMMENT),
        (payload, variables) => {
          return payload.comment.commentor === userId;
        },
      );
    },
  },

Question: Subscription resolver never called

Hi Marc. Thanks for sharing what seems to be a very useful tool! As new as GraphQL is to me, I can’t get my subscription resolver to trigger at all. Would you be willing to take a quick look at this and share any obvious insights I’m missing (note that this is all client-side, perhaps GraphQL can't be used like I'm intending?). Many thanks!

/*
Database.subscribeEntity is just a utility around firestore.onSnapshot 
It returns the unsubscribe function
*/
const ps = new PubSub();
ps.registerHandler('ENTITY_UPDATE', broadcast => 
    Database.subscribeEntity( '4uKadJUdvbhDtwc3ofUEfAkwwob2', (data) => {
        broadcast({test: 'test string'})
    })
);

var subscribeType = new GraphQLObjectType({
    name: 'Subscription', 
    fields: {
        entityUpdate: {
            type: GraphQLString,
            subscribe: () => {
                console.log('I am never called');
                return ps.asyncIterator('ENTITY_UPDATE');
            }
        }
    }
});

var queryType = new GraphQLObjectType({ ... });

var testSchema = new GraphQLSchema({query: queryType, subscription: subscribeType});
var testSubscriptionQuery = `subscription watchEntity {
    entityUpdate 
}`
graphql(testSchema, testSubscriptionQuery).then((response) => {
    console.log(response);
});

`

[docs] Worthwhile mentioning how to use with subscribeToMore? (+ possible caveats)

I was scratching my head for quite a while about the behavior of this (based on the full example) compared to simply publishing directly on mutations with something like graphql-yoga's pubsub.

Seeing how I suppose neither using the apollo-client, nor subscribeToMore is particularly rare, I wondered whether it would be worth mentioning in the README that if one uses it, one has to skip broadcasting the initial snapshot. (I keep track of it with an isInitialSnapshot in the handler.)

This has also made me realize that in a scenario where you have e.g. 1000 documents in that collection and hundreds of people per hour loading up the page, that's a lot of unnecessary load and traffic. Maybe this would also be good to point out?

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.