UNPKG

@ssb-graphql/pataka

Version:

Ahau's Pataka GraphQL types and resolvers for Secure Scuttlebutt

21 lines (19 loc) 575 B
const pull = require('pull-stream') const { GraphQLError } = require('graphql') module.exports = function CountCommunities (sbot) { return function countCommunities (cb) { pull( sbot.messagesByType({ type: 'profile/community' }), pull.filter(m => { const { tangles } = m.value.content if (!tangles) return false if (!tangles.profile) return false return tangles.profile.root === null }), pull.collect((err, msgs) => { if (err) cb(new GraphQLError(err)) cb(null, msgs.length) }) ) } }