fun mapVariable()

in graphql-dgs/src/main/kotlin/com/netflix/graphql/dgs/internal/utils/MultipartVariableMapper.kt [79:114]


    fun mapVariable(
        objectPath: String,
        variables: MutableMap<String, Any>,
        part: MultipartFile,
    ) {
        val segments = PERIOD.split(objectPath)

        if (segments.size < 2) {
            throw VariableMappingException("object-path in map must have at least two segments")
        } else if ("variables" != segments[0]) {
            throw VariableMappingException("can only map into variables")
        }

        var currentLocation: Any = variables
        for (i in 1 until segments.size) {
            val segmentName = segments[i]
            if (i == segments.size - 1) {
                if (currentLocation is Map<*, *>) {
                    if (null != MAP_MAPPER.set(currentLocation as MutableMap<String, Any>, segmentName, part)) {
                        throw VariableMappingException("expected null value when mapping $objectPath")
                    }
                } else {
                    if (null != LIST_MAPPER.set(currentLocation as MutableList<Any>, segmentName, part)) {
                        throw VariableMappingException("expected null value when mapping $objectPath")
                    }
                }
            } else {
                currentLocation =
                    if (currentLocation is Map<*, *>) {
                        MAP_MAPPER.recurse(currentLocation as MutableMap<String, Any>, segmentName)
                    } else {
                        LIST_MAPPER.recurse(currentLocation as MutableList<Any>, segmentName)
                    }
            }
        }
    }