Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor schema augmentation to have hooks for customization #224

Merged
merged 1 commit into from
May 20, 2021
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
324 changes: 319 additions & 5 deletions core/src/main/kotlin/org/neo4j/graphql/AugmentationHandler.kt

Large diffs are not rendered by default.

280 changes: 0 additions & 280 deletions core/src/main/kotlin/org/neo4j/graphql/BuildingEnv.kt

This file was deleted.

17 changes: 6 additions & 11 deletions core/src/main/kotlin/org/neo4j/graphql/ExtensionFunctions.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
package org.neo4j.graphql

import graphql.language.Description
import graphql.language.VariableReference
import graphql.schema.GraphQLArgument
import graphql.schema.GraphQLInputType
import graphql.schema.GraphQLType
import org.neo4j.cypherdsl.core.*
import java.util.*

fun <T> Iterable<T>.joinNonEmpty(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): String {
return if (iterator().hasNext()) joinTo(StringBuilder(), separator, prefix, postfix, limit, truncated, transform).toString() else ""
}

fun input(name: String, type: GraphQLType): GraphQLArgument {
return GraphQLArgument
.newArgument()
.name(name)
.type((type.ref() as? GraphQLInputType)
?: throw IllegalArgumentException("${type.innerName()} is not allowed for input")).build()
}

fun queryParameter(value: Any?, vararg parts: String?): Parameter<Any> {
val name = when (value) {
is VariableReference -> value.name
Expand All @@ -36,3 +27,7 @@ fun PropertyContainer.id(): FunctionInvocation = when (this) {
}

fun String.toCamelCase(): String = Regex("[\\W_]([a-z])").replace(this) { it.groupValues[1].toUpperCase() }

fun <T> Optional<T>.unwrap(): T? = orElse(null)

fun String.asDescription() = Description(this, null, this.contains("\n"))
Loading