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

This adds the ability to track the total number of ids to be hydrated #355

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

bbakerman
Copy link
Collaborator

This adds the ability to track the total number of ids to be hydrated plus per call how many we are acting on

Please make sure you consider the following:

  • [n/a ] Add tests that use __typename in queries
  • [ n/a] Does this change work with all nadel transformations (rename, type rename, hydration, etc)? Add tests for this.
  • [ n/a] Is it worth using hints for this change in order to be able to enable a percentage rollout?
  • [n/a ] Do we need to add integration tests for this change in the graphql gateway?
  • [ n/a] Do we need a pollinator check for this?

@@ -12,6 +12,7 @@ import graphql.nadel.enginekt.transform.hydration.batch.NadelBatchHydrationInput
import graphql.nadel.enginekt.transform.hydration.batch.NadelBatchHydrationObjectIdFieldBuilder.makeObjectIdField
import graphql.nadel.enginekt.transform.query.NFUtil
import graphql.nadel.enginekt.transform.result.json.JsonNode
import graphql.nadel.enginekt.util.CountedBox
import graphql.nadel.enginekt.util.deepClone
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

CountBox is a box class that has some object and associated count. Is there a Kotlin native equivalent ?

counter += hydrationBox.count
hydrationBox.boxedObject
}
val executableField = makeActorQueries(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

a single executableField can be N hydration ids eg usersByIds(ids : ["1","2","n"])

So we have 1 field with a count of N associated with it

): List<ExecutableNormalizedField> {
val argBatches = NadelBatchHydrationInputBuilder.getInputValueBatches(
): List<CountedBox<ExecutableNormalizedField>> {
val boxedArgBatches = NadelBatchHydrationInputBuilder.getInputValueBatches(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its the input values that are the key here - a set M parent nodes can lets to N ids to be hydrated

@@ -140,7 +146,7 @@ internal class NadelHydrationInputBuilder private constructor(
)
}

private fun getResultValue(
private fun getSingleResultValue(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

renamed because if you look at it - its does emptyOrSingle on the list of values

/**
* A box class that holds some value and a count associated with it
*/
data class CountedBox<T> (val boxedObject : T, val count : Int)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I know - its a Pair<T,Int> but I think this is semantically more meaningful

}

private fun getBatchInputValues(
instruction: NadelBatchHydrationFieldInstruction,
parentNodes: List<JsonNode>,
aliasHelper: NadelAliasHelper,
): List<Pair<NadelHydrationActorInputDef, NormalizedInputValue>> {
): List<Pair<NadelHydrationActorInputDef, CountedBox<NormalizedInputValue>>> {
Copy link
Member

Choose a reason for hiding this comment

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

this conflicts now with the changes that I made to support multi tenanted hydrations
I think it should be something like

private fun getBatchInputValues(
        instruction: NadelBatchHydrationFieldInstruction,
        parentNodes: List<JsonNode>,
        aliasHelper: NadelAliasHelper,
        hooks: ServiceExecutionHooks,
    ): List<Pair<NadelHydrationActorInputDef, CountedBox<NormalizedInputValue>>> {
        val batchSize = instruction.batchSize

        val (batchInputDef, batchInputValueSource) = getBatchInputDef(instruction) ?: return emptyList()
        val actorBatchArgDef = instruction.actorFieldDef.getArgument(batchInputDef.name)

        val fieldResultValues = getFieldResultValues(batchInputValueSource, parentNodes, aliasHelper)

        val partitionedArgumentList = when (hooks) {
            is NadelEngineExecutionHooks -> hooks.partitionBatchHydrationArgumentList(fieldResultValues, instruction)
            else -> listOf(fieldResultValues)
        }

        return partitionedArgumentList.flatMap { it.chunked(size = batchSize) }
            .map { chunkedFieldResultValues ->
                val normalizedInputValue = NormalizedInputValue(
                    GraphQLTypeUtil.simplePrint(actorBatchArgDef.type),
                    javaValueToAstValue(chunkedFieldResultValues),
                )
                batchInputDef to CountedBox(normalizedInputValue, chunkedFieldResultValues.size)
            }
    }

@temaEmelyan
Copy link
Member

looks good imo, just the merge conflicts

temaEmelyan
temaEmelyan previously approved these changes Jan 10, 2022
@gnawf
Copy link
Collaborator

gnawf commented Jan 12, 2022

Hmmm I'm very iffy on this. I get that we need this info, however I'd much rather track this in some sort of context object per hydration/query execution (which I think we may need for multitenanted hydrations that Artyom is working on, see my comment on that PR), rather than mess with the return type just to return an object 20 times in the hierarchy.

As an aside, I really want to add something like Dagger or kotlin-inject and clean up the way we pass around arguments and clean up how some objects are scoped to reduce the number of function parameters…

…cts-to-be-hydrated

# Conflicts:
#	engine-nextgen/src/main/kotlin/graphql/nadel/enginekt/transform/hydration/NadelHydrationFieldsBuilder.kt
#	engine-nextgen/src/main/kotlin/graphql/nadel/enginekt/transform/hydration/batch/NadelBatchHydrationInputBuilder.kt
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.

3 participants