0

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

none
  • 1,699
  • 2
  • 13
  • 18

2 Answers2

2

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

sorenbs
  • 749
  • 4
  • 7
  • @sorenbs is there any time estimation on when native support for geo queries will be available? :) – Lukas Jun 17 '17 at 07:24
  • @LucèBrùlè We don't have a concrete timeline yet. Please subscribe to this issue for updates https://github.com/graphcool/feature-requests/issues/28 – sorenbs Jun 18 '17 at 11:52
1

You may want to check out apollo-link-algolia to use Algolia service with Apollo directly from the client. This package is a simple wrapper around algoliasearch-helper-js. If you want to use it to execute geo queries it is as simple as creating following query in GraphQL:

const LOCATIONS_QUERY = gql`
  query LocationsQuery {
    locationsInRadius @algolia(index: "dev_LOCATIONS", aroundLatLng: "40.71, -74.01", aroundRadius: 1000)
  }
`
jano
  • 735
  • 7
  • 20