-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from jducoeur/add_graphql
Add GraphQL Support
- Loading branch information
Showing
23 changed files
with
1,268 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
17 changes: 17 additions & 0 deletions
17
querki/scala/shared/src/main/scala/querki/graphql/GraphQLFunctions.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package querki.graphql | ||
|
||
import scala.concurrent.Future | ||
|
||
trait GraphQLFunctions { | ||
/** | ||
* Run the given GraphQL expression, and return the result. | ||
* | ||
* Note that the result is a JSON String, which will contain errors if there are any. This should never | ||
* return a failed Future. | ||
* | ||
* @param graphQL a GraphQL expression that is legal for Querki | ||
* @param pretty iff true, the resulting String will be pretty-printed | ||
* @return the resulting JSON structure, rendered as a String | ||
*/ | ||
def runGraphQL(graphQL: String, pretty: Boolean = false): Future[String] | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package controllers | ||
|
||
import java.nio.charset.StandardCharsets | ||
|
||
import autowire._ | ||
import javax.inject.{Inject, Provider} | ||
import querki.globals._ | ||
import querki.graphql.GraphQLFunctions | ||
|
||
import scala.concurrent.Future | ||
|
||
class GraphQLController @Inject() (val appProv:Provider[play.api.Application]) extends ApplicationBase { | ||
def graphQL(ownerId: String, spaceIdStr: String) = withLocalClient(ownerId, spaceIdStr) { (rc, client) => | ||
val resultOpt = for { | ||
rawBuffer <- rc.request.body.asRaw | ||
bytes <- rawBuffer.asBytes() | ||
query = bytes.decodeString(StandardCharsets.UTF_8) | ||
} | ||
yield client[GraphQLFunctions].runGraphQL(query).call() | ||
|
||
resultOpt.map { resultFut => | ||
resultFut.map(Ok(_)) | ||
}.getOrElse( | ||
Future.successful(BadRequest("The content-type should be 'application/graphql', and there must be UTF-8 encoded GraphQL in the body"))) | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.