Skip to content

Commit 713b696

Browse files
samuelAndalonSamuel Vazquez
and
Samuel Vazquez
authored
feat(8.x.x): singleton property data fetcher (#2089)
Co-authored-by: Samuel Vazquez <[email protected]>
1 parent 2318398 commit 713b696

File tree

12 files changed

+210
-86
lines changed

12 files changed

+210
-86
lines changed

.github/workflows/build-examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
run: ./gradlew clean build
3838

3939
- name: Archive examples failure build reports
40-
uses: actions/upload-artifact@v3
40+
uses: actions/upload-artifact@v4
4141
if: failure()
4242
with:
4343
name: build-examples-reports

.github/workflows/build-libraries.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
run: ./gradlew clean build
2828

2929
- name: Archive failure build reports
30-
uses: actions/upload-artifact@v3
30+
uses: actions/upload-artifact@v4
3131
if: failure()
3232
with:
3333
name: build-reports

.github/workflows/plugin-it.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Android Test
2626
run: ./gradlew build
2727
- name: Archive failures
28-
uses: actions/upload-artifact@v3
28+
uses: actions/upload-artifact@v4
2929
if: failure()
3030
with:
3131
name: gradle-plugin-android-build-reports
@@ -53,7 +53,7 @@ jobs:
5353
- name: Integration Tests
5454
run: ./gradlew build
5555
- name: Archive failures
56-
uses: actions/upload-artifact@v3
56+
uses: actions/upload-artifact@v4
5757
if: failure()
5858
with:
5959
name: gradle-plugin-build-reports
@@ -82,7 +82,7 @@ jobs:
8282
- name: Integration Tests
8383
run: ./gradlew build
8484
- name: Archive failures
85-
uses: actions/upload-artifact@v3
85+
uses: actions/upload-artifact@v4
8686
if: failure()
8787
with:
8888
name: maven-plugin-build-reports

.github/workflows/release-code.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
PLUGIN_PORTAL_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }}
3939

4040
- name: Archive failure build reports
41-
uses: actions/upload-artifact@v3
41+
uses: actions/upload-artifact@v4
4242
if: failure()
4343
with:
4444
name: build-reports

generator/graphql-kotlin-schema-generator/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ tasks {
1919
limit {
2020
counter = "INSTRUCTION"
2121
value = "COVEREDRATIO"
22-
minimum = "0.96".toBigDecimal()
22+
minimum = "0.95".toBigDecimal()
2323
}
2424
limit {
2525
counter = "BRANCH"
2626
value = "COVEREDRATIO"
27-
minimum = "0.92".toBigDecimal()
27+
minimum = "0.91".toBigDecimal()
2828
}
2929
}
3030
}

generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/execution/KotlinDataFetcherFactoryProvider.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 Expedia, Inc
2+
* Copyright 2025 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -64,3 +64,12 @@ open class SimpleKotlinDataFetcherFactoryProvider : KotlinDataFetcherFactoryProv
6464
PropertyDataFetcher(kProperty.getter)
6565
}
6666
}
67+
68+
/**
69+
* [SimpleSingletonKotlinDataFetcherFactoryProvider] is a specialization of [SimpleKotlinDataFetcherFactoryProvider] that will provide a
70+
* a [SingletonPropertyDataFetcher] that should be used to target property resolutions without allocating a DataFetcher per property
71+
*/
72+
open class SimpleSingletonKotlinDataFetcherFactoryProvider : SimpleKotlinDataFetcherFactoryProvider() {
73+
override fun propertyDataFetcherFactory(kClass: KClass<*>, kProperty: KProperty<*>): DataFetcherFactory<Any?> =
74+
SingletonPropertyDataFetcher.getFactoryAndRegister(kClass, kProperty)
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.expediagroup.graphql.generator.execution
2+
3+
import graphql.schema.DataFetcher
4+
import graphql.schema.DataFetcherFactory
5+
import graphql.schema.DataFetchingEnvironment
6+
import graphql.schema.GraphQLFieldDefinition
7+
import graphql.schema.LightDataFetcher
8+
import java.util.concurrent.ConcurrentHashMap
9+
import java.util.function.Supplier
10+
import kotlin.reflect.KClass
11+
import kotlin.reflect.KProperty
12+
13+
/**
14+
* Singleton Property [DataFetcher] that stores references to underlying properties getters.
15+
*/
16+
internal object SingletonPropertyDataFetcher : LightDataFetcher<Any?> {
17+
18+
private val factory: DataFetcherFactory<Any?> = DataFetcherFactory<Any?> { SingletonPropertyDataFetcher }
19+
20+
private val getters: ConcurrentHashMap<String, KProperty.Getter<*>> = ConcurrentHashMap()
21+
22+
fun getFactoryAndRegister(kClass: KClass<*>, kProperty: KProperty<*>): DataFetcherFactory<Any?> {
23+
getters.computeIfAbsent("${kClass.java.name}.${kProperty.name}") {
24+
kProperty.getter
25+
}
26+
return factory
27+
}
28+
29+
override fun get(
30+
fieldDefinition: GraphQLFieldDefinition,
31+
sourceObject: Any?,
32+
environmentSupplier: Supplier<DataFetchingEnvironment>
33+
): Any? =
34+
sourceObject?.let {
35+
getters["${sourceObject.javaClass.name}.${fieldDefinition.name}"]?.call(sourceObject)
36+
}
37+
38+
override fun get(environment: DataFetchingEnvironment): Any? =
39+
environment.getSource<Any?>()?.let { sourceObject ->
40+
getters["${sourceObject.javaClass.name}.${environment.fieldDefinition.name}"]?.call(sourceObject)
41+
}
42+
}

0 commit comments

Comments
 (0)