DEV Community

Discussion on: Geospatial Queries on FaunaDB

Collapse
 
potato_potaro profile image
Taro Woollett-Chiba

Hey Jon! Thank you so much for reading and dropping a comment! As you mentioned, the faunadb-geo lib is performing the necessary S2 calculations and then passing the results to the request for index searches. I did this for the sake of development speed. It might be possible to re-implement critical parts (if not entirely) of S2's logic in FQL, but that would require a significant amount of work (there's a lot that happens under the hood for S2). I'm still considering this route for the future, but for now, the client-side S2 generation will have to suffice. That being side, if you're using NPM/Yarn on the frontend, you can use the faunadb-geo lib from there, and if it concerns you, implement FQL/UDFs to limit client requests (although it'd be a tad bit more work). I'd also be interested in potentially implementing such things in the package, so feel free to open an issue. Cheers.

Collapse
 
bristoljon profile image
Jon Wyatt

Thanks, finally picking this up now and your faunadb-geo lib is great! I've been very quickly able to filter by location using it though I do have a couple of further questions though:

As I mentioned I was mostly using graphql for it's convenience of fetching the data I want. So whats the best way of returning an object for each matching document with all the fields required rather than just the list of values specified by the index? Especially where I want to pull values out of other collections that are referenced in the document I've geo searched on..

Seems like the object would have to be constructed manually from the results. Basically doing what FaunaDB does automagically when resolving a graphql query but just wondered if you know of another way?

The other question is, how can you pass additional search terms to the index? So if you want to also allow filtering by other fields as well as geohash. Is there a way to pass through those parameters to the index?

Thanks again for the great library and the clear explanations given in this article!

Thread Thread
 
potato_potaro profile image
Taro Woollett-Chiba

Hey Jon, regarding GraphQL, I assume you're strictly using Fauna's implementation of it? If so, as you mentioned, writing a UDF along the lines of this docs.fauna.com/fauna/current/api/g... should do the trick. It might also be possible to simply rely on the @index directive, however, I haven't tested this yet.

As for passing additional search terms, your best bet is to create additional indexes and perform those searches outside of the index used for GeoSearch. The input can be cleanly combined in a UDF and assigned to a GraphQL query using @resolver.

Let me know if I missed anything or didn't satisfactorily answer your questions. Cheers.

Thread Thread
 
ryanpwaldon profile image
Ryan Waldon

Hey Taro!

I'm using GraphQL + UDFs, although I'm still unsure how to get your GeoSearch function working inside the UDF 😅

I've tried passing the FQL generated by GeoSearch into my UDF as a string, but AFAIK, there's no way to evaluate this is FQL once inside the UDF.

Any chance you could provide some insight into how to get this working?

Thanks :)