Skip to content

Commit

Permalink
Never wiring factory tweaks (#642)
Browse files Browse the repository at this point in the history
* Tiny tweak to share the same DF object

* Tiny tweak to share the same DF object - bump graphql-java

* Added a NEVER DFF

* Added a NEVER DFF - no default in wiring factory

* Added a NEVER DFF - no default in wiring factory - PR feedback tweaks
  • Loading branch information
bbakerman authored Jan 8, 2025
1 parent 0a5d283 commit 4a63d8f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def releaseVersion = System.env.RELEASE_VERSION
version = releaseVersion ? releaseVersion : getDevelopmentVersion()
group = "com.atlassian"
allprojects {
description = "Nadel is a Java library that combines multiple GrahpQL services together into one API."
description = "Nadel is a Kotlin library that combines multiple GraphQL services together into one GraphQL API."
}
gradle.buildFinished { buildResult ->
println "*******************************"
Expand Down
2 changes: 1 addition & 1 deletion lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id("com.bnorm.power.kotlin-power-assert")
}

val graphqlJavaVersion = "0.0.0-2024-09-03T03-36-42-d6dbf61"
val graphqlJavaVersion = "0.0.0-2024-11-28T03-45-06-a3fcfcb"
val slf4jVersion = "1.7.25"

dependencies {
Expand Down
6 changes: 5 additions & 1 deletion lib/src/main/java/graphql/nadel/NadelSchemas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data class NadelSchemas(
internal var overallWiringFactory: WiringFactory = NeverWiringFactory()
internal var underlyingWiringFactory: WiringFactory = NeverWiringFactory()


internal var serviceExecutionFactory: ServiceExecutionFactory? = null

// .nadel files
Expand Down Expand Up @@ -224,7 +225,10 @@ data class NadelSchemas(
private fun createEngineSchema(services: List<Service>): GraphQLSchema {
val overallSchemaGenerator = OverallSchemaGenerator()
val serviceRegistries = services.map(Service::definitionRegistry)
val schema = overallSchemaGenerator.buildOverallSchema(serviceRegistries, builder.overallWiringFactory)
val schema = overallSchemaGenerator.buildOverallSchema(
serviceRegistries,
builder.overallWiringFactory
)
val newSchema = builder.schemaTransformationHook.apply(schema, services)

// make sure that the overall schema has the standard scalars in
Expand Down
43 changes: 28 additions & 15 deletions lib/src/main/java/graphql/nadel/schema/NeverWiringFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import graphql.language.Value
import graphql.scalars.ExtendedScalars
import graphql.schema.Coercing
import graphql.schema.DataFetcher
import graphql.schema.DataFetcherFactory
import graphql.schema.GraphQLCodeRegistry
import graphql.schema.GraphQLScalarType
import graphql.schema.TypeResolver
import graphql.schema.idl.FieldWiringEnvironment
Expand Down Expand Up @@ -79,39 +81,50 @@ open class NeverWiringFactory : WiringFactory {
}
}

override fun providesTypeResolver(environment: InterfaceWiringEnvironment): Boolean {
final override fun providesTypeResolver(environment: InterfaceWiringEnvironment): Boolean {
return true
}

override fun getTypeResolver(environment: InterfaceWiringEnvironment): TypeResolver {
return TypeResolver {
assertShouldNeverHappen("This interface type resolver should NEVER be called from Nadel")
}
final override fun getTypeResolver(environment: InterfaceWiringEnvironment): TypeResolver {
return NEVER_TR
}

override fun providesTypeResolver(environment: UnionWiringEnvironment): Boolean {
final override fun providesTypeResolver(environment: UnionWiringEnvironment): Boolean {
return true
}

override fun getTypeResolver(environment: UnionWiringEnvironment): TypeResolver {
final override fun getTypeResolver(environment: UnionWiringEnvironment): TypeResolver {
return TypeResolver {
assertShouldNeverHappen("This union type resolver should NEVER be called from Nadel")
}
}

override fun providesDataFetcher(environment: FieldWiringEnvironment): Boolean {
return true
final override fun providesDataFetcher(environment: FieldWiringEnvironment): Boolean {
return false
}

override fun getDataFetcher(environment: FieldWiringEnvironment): DataFetcher<*> {
return DataFetcher {
assertShouldNeverHappen<Any?>("This data fetcher should NEVER be called from Nadel")
}
final override fun getDataFetcher(environment: FieldWiringEnvironment): DataFetcher<*> {
return assertShouldNeverHappen("getDataFetcher should NEVER be called from Nadel - we returned false")
}

final override fun getDefaultDataFetcher(environment: FieldWiringEnvironment): DataFetcher<*>? {
return null
}

override fun getDefaultDataFetcher(environment: FieldWiringEnvironment): DataFetcher<*> {
return DataFetcher {

companion object {
val NEVER_TR = TypeResolver {
assertShouldNeverHappen("This interface type resolver should NEVER be called from Nadel")
}
private val NEVER_DF = DataFetcher {
assertShouldNeverHappen<Any?>("This data fetcher should NEVER be called from Nadel")
}
private val NEVER_DFF = DataFetcherFactory {
NEVER_DF
}

val NEVER_CODE_REGISTRY: GraphQLCodeRegistry = GraphQLCodeRegistry.newCodeRegistry()
.defaultDataFetcher(NEVER_DFF).build()

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ internal class OverallSchemaGenerator {
val schemaGenerator = SchemaGenerator()
val runtimeWiring = RuntimeWiring.newRuntimeWiring()
.wiringFactory(wiringFactory)
.codeRegistry(
NeverWiringFactory.NEVER_CODE_REGISTRY
)
.build()

return schemaGenerator.makeExecutableSchema(createTypeRegistry(serviceRegistries), runtimeWiring)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ internal class UnderlyingSchemaGenerator {
val schemaGenerator = SchemaGenerator()
val runtimeWiring = RuntimeWiring.newRuntimeWiring()
.wiringFactory(wiringFactory)
.codeRegistry(
NeverWiringFactory.NEVER_CODE_REGISTRY
)
.build()
return try {
schemaGenerator.makeExecutableSchema(underlyingTypeDefinitions, runtimeWiring)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ import java.util.concurrent.ConcurrentHashMap
class GatewaySchemaWiringFactory : NeverWiringFactory() {
private val passThruScalars: MutableMap<String, GraphQLScalarType> = ConcurrentHashMap()

override fun providesScalar(env: ScalarWiringEnvironment): Boolean {
val scalarName = env.scalarTypeDefinition.name
override fun providesScalar(environment: ScalarWiringEnvironment): Boolean {
val scalarName = environment.scalarTypeDefinition.name
return if (defaultScalars.containsKey(scalarName)) {
true
} else !ScalarInfo.isGraphqlSpecifiedScalar(scalarName)
}

override fun getScalar(env: ScalarWiringEnvironment): GraphQLScalarType {
val scalarName = env.scalarTypeDefinition.name
override fun getScalar(environment: ScalarWiringEnvironment): GraphQLScalarType {
val scalarName = environment.scalarTypeDefinition.name
val scalarType = defaultScalars[scalarName]
return scalarType ?: passThruScalars.computeIfAbsent(scalarName) {
passThruScalar(env)
passThruScalar(environment)
}
}

Expand Down

0 comments on commit 4a63d8f

Please sign in to comment.