Skip to content

Conversation

gnawf
Copy link
Collaborator

@gnawf gnawf commented Aug 14, 2025

Builds on #693 to create a more cohesive context system for execution.

Previously we

  1. NadelExecutionContext one for every call to Nadel.execute
  2. NadelServiceExecutionContext one for every call to NextgenEngine.executeTopLevelField
  3. NadelTransformServiceExecutionContext one for every transform per operation execution.
  4. NadelTransform.State one for every field that the transform runs on.

So now we have

  1. NadelExecutionContext one for every call to Nadel.execute
  2. NadelOperationExecutionContext one for every call to NextgenEngine.executeTopLevelField
  3. NadelTransformOperationContext one for every transform per operation execution.
  4. NadelTransformFieldContext one for every field that the transform runs on.

So these classes were renamed

NadelServiceExecutionContextNadelOperationExecutionContext
NadelTransformServiceExecutionContextNadelTransformOperationContext
NadelTransform.StateNadelTransformFieldContext

Some other renames

NadelTransform.isApplicable -> NadelTransform.getTransformFieldContext
NadelTransform.buildContext -> NadelTransform.getTransformOperationContext

Each of the contexts has a reference to the parent context, so we have a good way to reference objects from upper portions of execution e.g. can do transformFieldContext.executionContext.engineSchema etc.

This has a good benefit in that our NadelTransform class is much simpler

interface NadelTransform<
    TransformOperationContext : NadelTransformOperationContext,
    TransformFieldContext : NadelTransformFieldContext<TransformOperationContext>,
    > {
    suspend fun getTransformOperationContext(
        operationExecutionContext: NadelOperationExecutionContext,
    ): TransformOperationContext

    suspend fun getTransformFieldContext(
        transformContext: TransformOperationContext,
        overallField: ExecutableNormalizedField,
    ): TransformFieldContext?

    suspend fun transformField(
        transformContext: TransformFieldContext,
        transformer: NadelQueryTransformer,
        field: ExecutableNormalizedField,
    ): NadelTransformFieldResult

    suspend fun transformResult(
        transformContext: TransformFieldContext,
        underlyingParentField: ExecutableNormalizedField?,
        resultNodes: JsonNodes,
    ): List<NadelResultInstruction>

    suspend fun onComplete(
        transformContext: TransformOperationContext,
        resultNodes: JsonNodes,
    ) {
    }
}

vs

interface NadelTransform<State : Any> {
    suspend fun buildContext(
        executionContext: NadelExecutionContext,
        serviceExecutionContext: NadelServiceExecutionContext,
        executionBlueprint: NadelOverallExecutionBlueprint,
        services: Map<String, Service>,
        service: Service,
        rootField: ExecutableNormalizedField,
        hydrationDetails: ServiceExecutionHydrationDetails?,
    ): NadelTransformServiceExecutionContext? {
        return null
    }

    suspend fun isApplicable(
        executionContext: NadelExecutionContext,
        serviceExecutionContext: NadelServiceExecutionContext,
        executionBlueprint: NadelOverallExecutionBlueprint,
        services: Map<String, Service>,
        service: Service,
        overallField: ExecutableNormalizedField,
        transformServiceExecutionContext: NadelTransformServiceExecutionContext?,
        hydrationDetails: ServiceExecutionHydrationDetails? = null,
    ): State?

    suspend fun transformField(
        executionContext: NadelExecutionContext,
        serviceExecutionContext: NadelServiceExecutionContext,
        transformer: NadelQueryTransformer,
        executionBlueprint: NadelOverallExecutionBlueprint,
        service: Service,
        field: ExecutableNormalizedField,
        state: State,
        transformServiceExecutionContext: NadelTransformServiceExecutionContext?,
    ): NadelTransformFieldResult

    suspend fun getResultInstructions(
        executionContext: NadelExecutionContext,
        serviceExecutionContext: NadelServiceExecutionContext,
        executionBlueprint: NadelOverallExecutionBlueprint,
        service: Service,
        overallField: ExecutableNormalizedField,
        underlyingParentField: ExecutableNormalizedField?,
        result: ServiceExecutionResult,
        state: State,
        nodes: JsonNodes,
        transformServiceExecutionContext: NadelTransformServiceExecutionContext?,
    ): List<NadelResultInstruction>

    suspend fun onComplete(
        executionContext: NadelExecutionContext,
        serviceExecutionContext: NadelServiceExecutionContext,
        executionBlueprint: NadelOverallExecutionBlueprint,
        service: Service,
        result: ServiceExecutionResult,
        nodes: JsonNodes,
        transformServiceExecutionContext: NadelTransformServiceExecutionContext?,
    ) {
    }
}

Copy link

github-actions bot commented Aug 14, 2025

Test Results

  605 files  +  605    605 suites  +605   1m 3s ⏱️ + 1m 3s
2 006 tests +2 006  1 491 ✅ +1 491  515 💤 +515  0 ❌ ±0 
2 014 runs  +2 014  1 499 ✅ +1 499  515 💤 +515  0 ❌ ±0 

Results for commit 686317c. ± Comparison against base commit 039d318.

♻️ This comment has been updated with latest results.

@gnawf gnawf force-pushed the refactor-contexts branch from c4505c3 to 53e749f Compare August 15, 2025 00:55
@gnawf gnawf marked this pull request as ready for review August 15, 2025 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant