meteoralgoliaapollographcool

Apollo subscription with graph.cool and Algolia


Now I have Meteor app with MongoDB geo-indexes.

And I'm using this kind of pub/sub:

 Meteor.publish('items', function itemsPublication(NELat, NELong, SWLat, SWLong) {

  return Items.find({
    $and: [
        {
            'till': {
                $gte: new Date()
            }
        },
        {
            'o': { $geoWithin: { $box: [ [ SWLong,SWLat], [ NELong, NELat] ] }  }
        }

    ]
   }, {
     fields: {
        o: 1,
        t: 1,
     }
   })
})

And I add some indexes, for example:

Item._ensureIndex({
    'till':1, 'o': '2dsphere' 
})

Everything working fine...

The main question is: is it possible to change Meteor pub/sub + MongoDB Geo-indexes to Apollo subs + graph.cool as backend + Algolia super fast Geo searching?

I need real reactivity without polling or something else...


Solution

  • Graphcool currently doesn't natively support spatial queries. For this reason you won't be able to get the reactive experience you are used to from Meteor and that Graphcool supports for other data types. We have an open feature request for this, and when merged Graphcool will be on par with Apollo in this regard.

    That said, here's how you can implement a workaround with Algolia while you wait for native support:

    1) Set up Algolia Integration for geo queries like described here https://www.graph.cool/docs/tutorials/algolia-auto-syncing-for-graphql-backends-aroozee9zu/#algolia-geosearch

    2) Set up a GraphQL subscription listening for Create, Update, Delete events for the model you are interested in

    3) When events are received, query the Algolia index to get the latest result