Skip to content

Commit 157423c

Browse files
authored
Delete old blueprint code (#656)
* Delete old blueprint code * Delete blueprint hint * Delete unused shadowing flag * Delete more of that flag
1 parent 1030fc8 commit 157423c

15 files changed

Lines changed: 50 additions & 1171 deletions

File tree

lib/src/main/java/graphql/nadel/Nadel.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import graphql.language.Document
1616
import graphql.nadel.engine.blueprint.NadelDefaultIntrospectionRunner
1717
import graphql.nadel.engine.blueprint.NadelIntrospectionRunnerFactory
1818
import graphql.nadel.engine.transform.NadelTransform
19-
import graphql.nadel.hints.NadelValidationBlueprintHint
2019
import graphql.nadel.hooks.NadelExecutionHooks
2120
import graphql.nadel.instrumentation.NadelInstrumentation
2221
import graphql.nadel.instrumentation.parameters.NadelInstrumentationCreateStateParameters
@@ -247,12 +246,8 @@ class Nadel private constructor(
247246
private var maxQueryDepth = Integer.MAX_VALUE
248247
private var maxFieldCount = Integer.MAX_VALUE
249248

250-
private var blueprintHint = NadelValidationBlueprintHint { false }
251-
252249
private var nadelValidation: NadelSchemaValidation? = null
253250

254-
private var latencyTracker: NadelInternalLatencyTracker? = null
255-
256251
fun schemas(schemas: NadelSchemas): Builder {
257252
this.schemas = schemas
258253
return this
@@ -373,11 +368,6 @@ class Nadel private constructor(
373368
return this
374369
}
375370

376-
fun blueprintHint(hint: NadelValidationBlueprintHint): Builder {
377-
this.blueprintHint = hint
378-
return this
379-
}
380-
381371
fun schemaValidation(nadelValidation: NadelSchemaValidation): Builder {
382372
this.nadelValidation = nadelValidation
383373
return this
@@ -400,7 +390,6 @@ class Nadel private constructor(
400390
services = services,
401391
transforms = transforms,
402392
introspectionRunnerFactory = introspectionRunnerFactory,
403-
blueprintHint = blueprintHint,
404393
nadelValidation = nadelValidation ?: NadelSchemaValidationFactory.create(),
405394
),
406395
services = services,

lib/src/main/java/graphql/nadel/NadelExecutionHints.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package graphql.nadel
33
import graphql.nadel.hints.AllDocumentVariablesHint
44
import graphql.nadel.hints.LegacyOperationNamesHint
55
import graphql.nadel.hints.NadelDeferSupportHint
6-
import graphql.nadel.hints.NadelServiceTypenameShadowingHint
76
import graphql.nadel.hints.NadelSharedTypeRenamesHint
87
import graphql.nadel.hints.NadelShortCircuitEmptyQueryHint
98
import graphql.nadel.hints.NadelVirtualTypeSupportHint
@@ -17,7 +16,6 @@ data class NadelExecutionHints(
1716
val sharedTypeRenames: NadelSharedTypeRenamesHint,
1817
val shortCircuitEmptyQuery: NadelShortCircuitEmptyQueryHint,
1918
val virtualTypeSupport: NadelVirtualTypeSupportHint,
20-
val serviceTypenameShadowing: NadelServiceTypenameShadowingHint,
2119
) {
2220
/**
2321
* Returns a builder with the same field values as this object.
@@ -37,7 +35,6 @@ data class NadelExecutionHints(
3735
private var shortCircuitEmptyQuery = NadelShortCircuitEmptyQueryHint { false }
3836
private var sharedTypeRenames = NadelSharedTypeRenamesHint { false }
3937
private var virtualTypeSupport = NadelVirtualTypeSupportHint { false }
40-
private var serviceTypenameShadowing = NadelServiceTypenameShadowingHint.default
4138

4239
constructor()
4340

@@ -83,11 +80,6 @@ data class NadelExecutionHints(
8380
return this
8481
}
8582

86-
fun serviceTypenameShadowing(flag: NadelServiceTypenameShadowingHint): Builder {
87-
serviceTypenameShadowing = flag
88-
return this
89-
}
90-
9183
fun build(): NadelExecutionHints {
9284
return NadelExecutionHints(
9385
legacyOperationNames,
@@ -97,7 +89,6 @@ data class NadelExecutionHints(
9789
sharedTypeRenames,
9890
shortCircuitEmptyQuery,
9991
virtualTypeSupport,
100-
serviceTypenameShadowing,
10192
)
10293
}
10394
}

lib/src/main/java/graphql/nadel/NextgenEngine.kt

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ import graphql.nadel.engine.NadelExecutionContext
1616
import graphql.nadel.engine.NadelIncrementalResultSupport
1717
import graphql.nadel.engine.NadelServiceExecutionContext
1818
import graphql.nadel.engine.blueprint.IntrospectionService
19-
import graphql.nadel.engine.blueprint.NadelExecutionBlueprintFactory
2019
import graphql.nadel.engine.blueprint.NadelIntrospectionRunnerFactory
21-
import graphql.nadel.engine.blueprint.NadelOverallExecutionBlueprintMigrator
2220
import graphql.nadel.engine.document.DocumentPredicates
2321
import graphql.nadel.engine.instrumentation.NadelInstrumentationTimer
2422
import graphql.nadel.engine.plan.NadelExecutionPlan
@@ -40,7 +38,6 @@ import graphql.nadel.engine.util.newServiceExecutionResult
4038
import graphql.nadel.engine.util.provide
4139
import graphql.nadel.engine.util.singleOfType
4240
import graphql.nadel.engine.util.strictAssociateBy
43-
import graphql.nadel.hints.NadelValidationBlueprintHint
4441
import graphql.nadel.hooks.NadelExecutionHooks
4542
import graphql.nadel.hooks.createServiceExecutionContext
4643
import graphql.nadel.instrumentation.NadelInstrumentation
@@ -55,7 +52,6 @@ import graphql.nadel.result.NadelResultMerger
5552
import graphql.nadel.result.NadelResultTracker
5653
import graphql.nadel.time.NadelInternalLatencyTracker
5754
import graphql.nadel.util.OperationNameUtil
58-
import graphql.nadel.util.getLogger
5955
import graphql.nadel.validation.NadelSchemaValidation
6056
import graphql.normalized.ExecutableNormalizedField
6157
import graphql.normalized.ExecutableNormalizedOperationFactory.createExecutableNormalizedOperationWithRawVariables
@@ -73,7 +69,6 @@ import kotlinx.coroutines.delay
7369
import kotlinx.coroutines.flow.onEach
7470
import kotlinx.coroutines.future.asCompletableFuture
7571
import kotlinx.coroutines.future.asDeferred
76-
import kotlinx.coroutines.future.await
7772
import kotlinx.coroutines.launch
7873
import kotlinx.coroutines.reactive.asFlow
7974
import kotlinx.coroutines.reactive.asPublisher
@@ -92,27 +87,13 @@ internal class NextgenEngine(
9287
services: List<Service>,
9388
transforms: List<NadelTransform<out Any>>,
9489
introspectionRunnerFactory: NadelIntrospectionRunnerFactory,
95-
blueprintHint: NadelValidationBlueprintHint,
9690
nadelValidation: NadelSchemaValidation,
9791
) {
9892
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
9993
private val services: Map<String, Service> = services.strictAssociateBy { it.name }
10094
private val engineSchemaIntrospectionService = IntrospectionService(engineSchema, introspectionRunnerFactory)
101-
private val overallExecutionBlueprint = NadelOverallExecutionBlueprintMigrator(
102-
hint = blueprintHint,
103-
old = NadelExecutionBlueprintFactory.create(
104-
engineSchema = engineSchema,
105-
services = services,
106-
),
107-
new = lazy {
108-
try {
109-
nadelValidation.validateAndGenerateBlueprint(NadelSchemas(engineSchema, services))
110-
} catch (e: Exception) {
111-
getLogger<NextgenEngine>().error("Unable to create validated blueprint", e)
112-
null
113-
}
114-
},
115-
)
95+
private val overallExecutionBlueprint = nadelValidation
96+
.validateAndGenerateBlueprint(NadelSchemas(engineSchema, services))
11697
private val executionPlanner = NadelExecutionPlanFactory.create(
11798
executionBlueprint = overallExecutionBlueprint,
11899
engine = this,

lib/src/main/java/graphql/nadel/engine/blueprint/NadelExecutionBlueprint.kt

Lines changed: 46 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -7,154 +7,38 @@ import graphql.nadel.engine.util.emptyOrSingle
77
import graphql.nadel.engine.util.makeFieldCoordinates
88
import graphql.nadel.engine.util.mapFrom
99
import graphql.nadel.engine.util.strictAssociateBy
10-
import graphql.nadel.hints.NadelValidationBlueprintHint
1110
import graphql.normalized.ExecutableNormalizedField
1211
import graphql.schema.FieldCoordinates
1312
import graphql.schema.GraphQLSchema
1413

1514
/**
1615
* Execution blueprint where keys are in terms of the overall schema.
1716
*/
18-
interface NadelOverallExecutionBlueprint {
19-
val engineSchema: GraphQLSchema
20-
21-
val fieldInstructions: Map<FieldCoordinates, List<NadelFieldInstruction>>
22-
23-
fun getUnderlyingTypeNamesForService(service: Service): Set<String>
24-
25-
fun getOverAllTypeNamesForService(service: Service): Set<String>
26-
27-
fun getUnderlyingTypeName(
28-
service: Service,
29-
overallTypeName: String,
30-
): String
31-
32-
fun getUnderlyingTypeName(overallTypeName: String): String
33-
34-
fun getRename(overallTypeName: String): NadelTypeRenameInstruction?
35-
36-
fun getOverallTypeName(
37-
service: Service,
38-
underlyingTypeName: String,
39-
): String
40-
41-
fun getServiceOwning(fieldCoordinates: FieldCoordinates): Service?
42-
}
43-
44-
/**
45-
* Can't put inline function inside interface, so made it an extension function.
46-
*
47-
* This is temporary until we delete [NadelOverallExecutionBlueprintMigrator].
48-
*/
49-
inline fun <reified T : NadelFieldInstruction> NadelOverallExecutionBlueprint.getInstructionInsideVirtualType(
50-
hydrationDetails: ServiceExecutionHydrationDetails?,
51-
backingField: ExecutableNormalizedField,
52-
): Map<GraphQLObjectTypeName, List<T>> {
53-
hydrationDetails ?: return emptyMap() // Need hydration to provide virtual hydration context
54-
55-
val backingFieldParentTypeName = backingField.objectTypeNames.singleOrNull()
56-
?: return emptyMap() // Don't support abstract types for now
57-
58-
val nadelHydrationContext = fieldInstructions[hydrationDetails.hydrationVirtualField]!!
59-
.asSequence()
60-
.filterIsInstance<NadelGenericHydrationInstruction>()
61-
.first() as? NadelHydrationFieldInstruction
62-
?: return emptyMap() // Virtual types only come about from standard hydrations, not batched
63-
64-
val virtualTypeContext = nadelHydrationContext.virtualTypeContext
65-
?: return emptyMap() // Not all hydrations create virtual types
66-
67-
val virtualType = virtualTypeContext.backingTypeToVirtualType[backingFieldParentTypeName]
68-
?: return emptyMap() // Not a virtual type
69-
70-
val fieldCoordinatesInVirtualType = makeFieldCoordinates(virtualType, backingField.name)
71-
72-
val instructions = fieldInstructions[fieldCoordinatesInVirtualType]
73-
?.filterIsInstance<T>()
74-
?.takeIf {
75-
it.isNotEmpty()
76-
}
77-
?: return emptyMap()
78-
79-
return mapOf(
80-
backingField.objectTypeNames.single() to instructions,
81-
)
82-
}
83-
84-
internal class NadelOverallExecutionBlueprintMigrator(
85-
private val hint: NadelValidationBlueprintHint,
86-
val old: NadelOverallExecutionBlueprint,
87-
val new: Lazy<NadelOverallExecutionBlueprint?>,
88-
) : NadelOverallExecutionBlueprint {
89-
private val impl: NadelOverallExecutionBlueprint
90-
get() {
91-
return if (hint.isNewBlueprintEnabled()) {
92-
new.value ?: old
93-
} else {
94-
old
95-
}
96-
}
97-
98-
override val engineSchema: GraphQLSchema
99-
get() = impl.engineSchema
100-
101-
override val fieldInstructions: Map<FieldCoordinates, List<NadelFieldInstruction>>
102-
get() = impl.fieldInstructions
103-
104-
override fun getUnderlyingTypeNamesForService(service: Service): Set<String> {
105-
return impl.getUnderlyingTypeNamesForService(service)
106-
}
107-
108-
override fun getOverAllTypeNamesForService(service: Service): Set<String> {
109-
return impl.getOverAllTypeNamesForService(service)
110-
}
111-
112-
override fun getUnderlyingTypeName(service: Service, overallTypeName: String): String {
113-
return impl.getUnderlyingTypeName(service, overallTypeName)
114-
}
115-
116-
override fun getUnderlyingTypeName(overallTypeName: String): String {
117-
return impl.getUnderlyingTypeName(overallTypeName)
118-
}
119-
120-
override fun getRename(overallTypeName: String): NadelTypeRenameInstruction? {
121-
return impl.getRename(overallTypeName)
122-
}
123-
124-
override fun getOverallTypeName(service: Service, underlyingTypeName: String): String {
125-
return impl.getOverallTypeName(service, underlyingTypeName)
126-
}
127-
128-
override fun getServiceOwning(fieldCoordinates: FieldCoordinates): Service? {
129-
return impl.getServiceOwning(fieldCoordinates)
130-
}
131-
}
132-
133-
internal data class NadelOverallExecutionBlueprintImpl(
134-
override val engineSchema: GraphQLSchema,
135-
override val fieldInstructions: Map<FieldCoordinates, List<NadelFieldInstruction>>,
17+
data class NadelOverallExecutionBlueprint(
18+
val engineSchema: GraphQLSchema,
19+
val fieldInstructions: Map<FieldCoordinates, List<NadelFieldInstruction>>,
13620
private val underlyingTypeNamesByService: Map<Service, Set<String>>,
13721
private val overallTypeNamesByService: Map<Service, Set<String>>,
13822
private val underlyingBlueprints: Map<String, NadelUnderlyingExecutionBlueprint>,
13923
private val coordinatesToService: Map<FieldCoordinates, Service>,
14024
private val typeRenamesByOverallTypeName: Map<String, NadelTypeRenameInstruction>,
141-
) : NadelOverallExecutionBlueprint {
25+
) {
14226
private fun setOfServiceTypes(
14327
map: Map<Service, Set<String>>,
14428
service: Service,
14529
): Set<String> {
14630
return (map[service] ?: error("Could not find service: ${service.name}"))
14731
}
14832

149-
override fun getUnderlyingTypeNamesForService(service: Service): Set<String> {
33+
fun getUnderlyingTypeNamesForService(service: Service): Set<String> {
15034
return setOfServiceTypes(underlyingTypeNamesByService, service)
15135
}
15236

153-
override fun getOverAllTypeNamesForService(service: Service): Set<String> {
37+
fun getOverAllTypeNamesForService(service: Service): Set<String> {
15438
return setOfServiceTypes(overallTypeNamesByService, service)
15539
}
15640

157-
override fun getUnderlyingTypeName(
41+
fun getUnderlyingTypeName(
15842
service: Service,
15943
overallTypeName: String,
16044
): String {
@@ -165,15 +49,15 @@ internal data class NadelOverallExecutionBlueprintImpl(
16549
return getUnderlyingBlueprint(service).typeInstructions.getUnderlyingName(overallTypeName)
16650
}
16751

168-
override fun getUnderlyingTypeName(overallTypeName: String): String {
52+
fun getUnderlyingTypeName(overallTypeName: String): String {
16953
return typeRenamesByOverallTypeName[overallTypeName]?.underlyingName ?: overallTypeName
17054
}
17155

172-
override fun getRename(overallTypeName: String): NadelTypeRenameInstruction? {
56+
fun getRename(overallTypeName: String): NadelTypeRenameInstruction? {
17357
return typeRenamesByOverallTypeName[overallTypeName]
17458
}
17559

176-
override fun getOverallTypeName(
60+
fun getOverallTypeName(
17761
service: Service,
17862
underlyingTypeName: String,
17963
): String {
@@ -184,10 +68,45 @@ internal data class NadelOverallExecutionBlueprintImpl(
18468
return getUnderlyingBlueprint(service).typeInstructions.getOverallName(underlyingTypeName)
18569
}
18670

187-
override fun getServiceOwning(fieldCoordinates: FieldCoordinates): Service? {
71+
fun getServiceOwning(fieldCoordinates: FieldCoordinates): Service? {
18872
return coordinatesToService[fieldCoordinates]
18973
}
19074

75+
inline fun <reified T : NadelFieldInstruction> getInstructionInsideVirtualType(
76+
hydrationDetails: ServiceExecutionHydrationDetails?,
77+
backingField: ExecutableNormalizedField,
78+
): Map<GraphQLObjectTypeName, List<T>> {
79+
hydrationDetails ?: return emptyMap() // Need hydration to provide virtual hydration context
80+
81+
val backingFieldParentTypeName = backingField.objectTypeNames.singleOrNull()
82+
?: return emptyMap() // Don't support abstract types for now
83+
84+
val nadelHydrationContext = fieldInstructions[hydrationDetails.hydrationVirtualField]!!
85+
.asSequence()
86+
.filterIsInstance<NadelGenericHydrationInstruction>()
87+
.first() as? NadelHydrationFieldInstruction
88+
?: return emptyMap() // Virtual types only come about from standard hydrations, not batched
89+
90+
val virtualTypeContext = nadelHydrationContext.virtualTypeContext
91+
?: return emptyMap() // Not all hydrations create virtual types
92+
93+
val virtualType = virtualTypeContext.backingTypeToVirtualType[backingFieldParentTypeName]
94+
?: return emptyMap() // Not a virtual type
95+
96+
val fieldCoordinatesInVirtualType = makeFieldCoordinates(virtualType, backingField.name)
97+
98+
val instructions = fieldInstructions[fieldCoordinatesInVirtualType]
99+
?.filterIsInstance<T>()
100+
?.takeIf {
101+
it.isNotEmpty()
102+
}
103+
?: return emptyMap()
104+
105+
return mapOf(
106+
backingField.objectTypeNames.single() to instructions,
107+
)
108+
}
109+
191110
private fun getUnderlyingBlueprint(service: Service): NadelUnderlyingExecutionBlueprint {
192111
val name = service.name
193112
return underlyingBlueprints[name] ?: error("Could not find service: $name")

0 commit comments

Comments
 (0)