Skip to content

Instantly share code, notes, and snippets.

@dwhitney
Created November 11, 2015 19:59
Show Gist options
  • Save dwhitney/d50a47d8431ec18f6b32 to your computer and use it in GitHub Desktop.
Save dwhitney/d50a47d8431ec18f6b32 to your computer and use it in GitHub Desktop.
def graphql: Endpoint[Json] = {
post(
"graphql" ? (body :: authOptReader :: contentTypeReader :: imageOptReader :: queryReader :: variablesReader)
){ (body: String, authOpt: Option[TokenUUID], contentType: String, image: Option[FileUpload], query: Option[String], variables: Option[String]) =>
contentType.take("multipart/form-data".length) match {
case "multipart/form-data" => {
for {
auth <- getAuthorization(authOpt)
r <- resolveQuery(query.get, auth, image, variables)
} yield (r)
}
case _ =>
val Xor.Right(req) = decode[GraphQLRequest](body)
for {
auth <- getAuthorization(authOpt)
r <- resolveQuery(req.query, auth, None, req.variables)
} yield (r)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment