-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
208 additions
and
51 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
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
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,64 @@ | ||
package models.sandbox | ||
|
||
import better.files._ | ||
import models.Application | ||
import models.auth.Credentials | ||
import services.graphql.GraphQLService | ||
import util.FutureUtils.serviceContext | ||
import util.tracing.TraceData | ||
|
||
import scala.sys.process._ | ||
import scala.util.control.NonFatal | ||
|
||
object GraphdocLogic { | ||
private[this] val d = "./doc/src/main/graphdoc".toFile | ||
|
||
def generate(creds: Credentials, app: Application, graphQLService: GraphQLService, argument: Option[String])(implicit td: TraceData) = { | ||
checkInstalled() | ||
if (argument.contains("force") && !d.exists) { | ||
d.createDirectories() | ||
} | ||
if (d.isDirectory) { | ||
run(creds, app, graphQLService) | ||
} else { | ||
throw new IllegalStateException(s"""Directory [${d.path}] doe not exist, pass "force" as an argument to create.""") | ||
} | ||
} | ||
|
||
private[this] val queryFilename = "IntrospectionQuery.graphql" | ||
private[this] val schemaFilename = "schema.json" | ||
|
||
private[this] lazy val introspectionQuery = Option(getClass.getClassLoader.getResourceAsStream(queryFilename)) match { | ||
case Some(q) => scala.io.Source.fromInputStream(q).getLines().mkString("\n") | ||
case None => throw new IllegalStateException(s"Cannot read [$queryFilename].") | ||
} | ||
|
||
private[this] def writeIntrospectionResult(creds: Credentials, app: Application, graphQLService: GraphQLService)(implicit td: TraceData) = try { | ||
val f = d / schemaFilename | ||
if (!f.exists) { | ||
f.createFile() | ||
} | ||
graphQLService.executeQuery(app, introspectionQuery, None, None, creds, debug = false).map(_.spaces2).map { json => | ||
f.overwrite(json) | ||
} | ||
} catch { | ||
case NonFatal(x) => throw new IllegalStateException(s"Cannot run graphdoc. Is it installed? (${x.getMessage})", x) | ||
} | ||
|
||
private[this] def run(creds: Credentials, app: Application, graphQLService: GraphQLService)(implicit td: TraceData) = { | ||
writeIntrospectionResult(creds, app, graphQLService).map { _ => | ||
val args = Seq("graphdoc", "--force", "-s", (d / schemaFilename).pathAsString, "-o", d.pathAsString) | ||
try { | ||
args.!! | ||
} catch { | ||
case NonFatal(x) => throw new IllegalStateException(s"Cannot run [$args]. (${x.getMessage})", x) | ||
} | ||
} | ||
} | ||
|
||
private[this] def checkInstalled() = try { | ||
Seq("graphdoc", "--help").!! | ||
} catch { | ||
case NonFatal(x) => throw new IllegalStateException(s"Cannot run graphdoc. Is it installed? (${x.getMessage})", x) | ||
} | ||
} |
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
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,99 @@ | ||
query IntrospectionQuery { | ||
__schema { | ||
queryType { name description kind} | ||
mutationType { name description kind } | ||
subscriptionType { name description kind } | ||
types { | ||
name | ||
kind | ||
description | ||
...FullType | ||
} | ||
directives { | ||
name | ||
description | ||
locations | ||
args { | ||
...InputValue | ||
} | ||
} | ||
} | ||
} | ||
|
||
fragment FullType on __Type { | ||
fields(includeDeprecated: true) { | ||
name | ||
description | ||
args { | ||
...InputValue | ||
} | ||
type { | ||
...TypeRef | ||
} | ||
isDeprecated | ||
deprecationReason | ||
} | ||
inputFields { | ||
...InputValue | ||
} | ||
interfaces { | ||
...TypeRef | ||
} | ||
enumValues(includeDeprecated: true) { | ||
name | ||
description | ||
isDeprecated | ||
deprecationReason | ||
} | ||
possibleTypes { | ||
...TypeRef | ||
} | ||
} | ||
|
||
fragment InputValue on __InputValue { | ||
name | ||
description | ||
type { ...TypeRef } | ||
defaultValue | ||
} | ||
|
||
fragment TypeRef on __Type { | ||
kind | ||
name | ||
description | ||
ofType { | ||
kind | ||
name | ||
description | ||
ofType { | ||
kind | ||
name | ||
description | ||
ofType { | ||
kind | ||
name | ||
description | ||
ofType { | ||
kind | ||
name | ||
description | ||
ofType { | ||
kind | ||
name | ||
description | ||
ofType { | ||
kind | ||
name | ||
description | ||
ofType { | ||
kind | ||
name | ||
description | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.