DEV Community

Discussion on: Geospatial Queries on FaunaDB

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 :)