Last active
November 26, 2019 16:19
-
-
Save duanebester/37fff5cc0e2541841ab27dc1cdebc09d to your computer and use it in GitHub Desktop.
GraphQL Server 0
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") | |
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