Skip to content

Commit

Permalink
Refactor schema augmentation to have hooks for customization (#224)
Browse files Browse the repository at this point in the history
Due to these changes, schema augmentation is no longer performed on the compiled graphql schema, but on the given type definitions. This will greatly simplify the extension of the neo4j schema with custom resolvers, such as with https://netflix.github.io/dgs/.
  • Loading branch information
Andy2003 authored May 20, 2021
1 parent e3c118e commit 5d69b71
Show file tree
Hide file tree
Showing 25 changed files with 1,128 additions and 900 deletions.
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

0 comments on commit 5d69b71

Please sign in to comment.