Skip to content

Provide easy access to context within dataProperty #104

Open
@jeggy

Description

@jeggy

Currently if I want to get access to the context within a dataLoader resolver I need to do the following:

dataProperty<Pair<Int, Int>, List<Value>>("valueList") {
  prepare { parent, ctx: Context -> ctx.userId to parent.id }
  loader { keys ->
    val dataMap: Map<Int, List<Value>> = loadValues(keys.first().first, keys.map { it.second })
    keys.map { ExecutionResult.Success(dataMap.getValue(it.second)) }
  }
}

It would be great if I didn't need to pass anything from the context from the prepare to the loader, so it could look more like something this:

dataProperty<Int, List<Value>>("valueList") {
  prepare { it.id }
  loader { parentIds: List<Int>, ctx: Context ->
    val dataMap: Map<Int, List<Value>> = loadValues(ctx.userId, parentIds)
    keys.map { ExecutionResult.Success(dataMap.getValue(it)) }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions