Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ dependencies {
testCompile "org.junit.jupiter:junit-jupiter-params:$junitVersion"
testRuntime "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
testCompile 'org.json:json:20180813'
testCompile 'com.graphql-java:graphql-java:2018-08-23T21-16-30-141b8e4'
testCompile 'com.graphql-java:graphql-java:9.0'
testCompile 'org.skyscreamer:jsonassert:1.5.0'
ktlint "com.github.shyiko:ktlint:0.27.0"
}

// graphql-java:
// 8.0 directives are NOT visible in introspection query
// 9.0 directives are visible in introspection query

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,33 @@ class GeneratorImpl {

val margin = " "
val primitiveScalars = listOf("Boolean", "Float", "ID", "Int", "String")
val primitiveDirectives = listOf("include", "skip", "defer", "deprecated")

fun generate(
input: String,
settings: GeneratorSettings
): String {
val response = Klaxon().parse<IntrospectionResponse>(input) ?: return ""

val output = printSchema(response) + printTypes(response, settings)
val output = printSchema(response) + printTypes(response, settings) + printDirectives(response, settings)

return output.trimIndent().trimIndent()
}

private fun printDirectives(response: IntrospectionResponse, settings: GeneratorSettings): String {
return response.data.schema.directives!!
.filter { !primitiveDirectives.contains(it.name) }
.sortedBy { it.name }
.map { "${printDescription(it, settings, false)}directive @${it.name}${printArguments(it.args, settings)} on ${printDirectiveLocation(it)}" }
.joinToString("\n\n")
}

private fun printDirectiveLocation(directive: GraphQLDirective): String {
return directive.locations
.sortedBy { it }
.joinToString(" | ")
}

private fun printSchema(response: IntrospectionResponse): String {
if (isCustomQueryType(response) || isCustomMutationType(response) || isCustomSubscriptionType(response)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ data class Schema(
val queryType: QueryType?,
val mutationType: MutationType? = null,
val subscriptionType: SubscriptionType? = null,
val types: List<GraphQLType>? = null
val types: List<GraphQLType>? = null,
val directives: List<GraphQLDirective>? = null
)

data class QueryType(val name: String)
Expand Down Expand Up @@ -48,3 +49,10 @@ data class GraphQLEnumType(
interface Descriptable {
val description: String
}

data class GraphQLDirective(
val name: String,
override val description: String = "",
val locations: List<String> = listOf(),
val args: List<GraphQLField> = listOf()
) : Descriptable
Loading