This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"bbox": { | |
"topLeft": { | |
"lat": "37.488854011108415", | |
"lon": "-120.18521828357393" | |
}, | |
"bottomRight": { | |
"lat": "18.496235092613475", | |
"lon": "-93.08337778423378" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"bbox": { | |
"topLeft": { | |
"lat": "37.488854011108415", | |
"lon": "-120.18521828357393" | |
}, | |
"bottomRight": { | |
"lat": "23.496235092613475", | |
"lon": "-93.08337778423378" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QueryParser.parse(query) match { | |
case Success(queryAst) => | |
val variables = fields.get("variables") match { | |
case Some(obj: JsObject) => obj | |
case _ => JsObject.empty | |
} | |
complete(executeGraphQLQuery(queryAst, None, variables)) | |
case Failure(error) => | |
complete(BadRequest, JsObject("error" -> JsString(error.getMessage))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private def executeGraphQLQuery( | |
query: Document, | |
operation: Option[String], // Not defined yet | |
vars: JsObject | |
)( | |
implicit ec: ExecutionContext | |
) = | |
Executor | |
.execute( | |
GraphQLSchema.SchemaDefinition, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object GraphQLServer { | |
val elastic = new Elastic( | |
ElasticProperties("http://localhost:9200") | |
) | |
def endpoint(requestJSON: JsValue)(implicit ec: ExecutionContext): Route = { | |
val JsObject(fields) = requestJSON | |
val JsString(query) = fields("query") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Elastic(props: ElasticProperties) extends ElasticHelpers { | |
implicit val ec: ExecutionContext = ExecutionContext.global | |
override val elasticProps: ElasticProperties = props | |
override val elasticClient = ElasticClient(JavaClient(elasticProps)) | |
def searchUsers(filter: Filter) = | |
elasticClient.execute { | |
search(USER_INDEX).bool(buildQuery(filter)) | |
}.map(resp => UsersResponse(resp.result.to[User], resp.result.totalHits)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Product { | |
id: number | |
} | |
function getId(product: Product): number { | |
return product.id; | |
} | |
// Does not work in development with typescript :sunglasses: | |
let product: Product = { id: null }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait ElasticHelpers { | |
final val USER_INDEX = "test-users" | |
final val COFFEE_SHOPS_INDEX = "test-coffee-shops" | |
val elasticProps: ElasticProperties | |
val elasticClient: ElasticClient | |
def searchUsers(filter: Filter): Future[SearchResponse[User]] | |
def searchCoffeeShops(filter: Filter): Future[CoffeeShopsResponse] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sangria.schema._ | |
import sangria.macros.derive._ | |
import sangria.marshalling.sprayJson._ | |
import models.responses._ | |
import models.variables._ | |
import models.common._ | |
object GraphQLSchema { | |
// Responses |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models.variables | |
import spray.json.DefaultJsonProtocol | |
import models.common.Location | |
// BBox.scala | |
case class BBox(topLeft: Location, bottomRight: Location) | |
object BBox extends DefaultJsonProtocol { | |
implicit val format = jsonFormat2(BBox.apply) | |
} |