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

Never wiring factory tweaks #642

Merged
merged 6 commits into from
Jan 8, 2025
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
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."
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bugged me

}
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we dont create a DF per field or make a CodeRegistry entry per field as well but rather use a default

}

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no default makes it use CodeRegistry default

}

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()

}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we apply the same thing to UnderlyingSchemaGenerator ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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
Loading