Skip to content

Instantly share code, notes, and snippets.

@duanebester
Last active November 26, 2019 16:19
Show Gist options
  • Save duanebester/37fff5cc0e2541841ab27dc1cdebc09d to your computer and use it in GitHub Desktop.
Save duanebester/37fff5cc0e2541841ab27dc1cdebc09d to your computer and use it in GitHub Desktop.
GraphQL Server 0
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")
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)))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment