|
| 1 | +/* |
| 2 | + * Copyright 2025 Expedia, Inc |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
1 | 17 | package com.expediagroup.graphql.generator.execution |
2 | 18 |
|
3 | 19 | import graphql.schema.DataFetcher |
@@ -31,27 +47,23 @@ internal object SingletonPropertyDataFetcher : LightDataFetcher<Any?> { |
31 | 47 | fieldDefinition: GraphQLFieldDefinition, |
32 | 48 | sourceObject: Any?, |
33 | 49 | environmentSupplier: Supplier<DataFetchingEnvironment> |
34 | | - ): Any? = |
35 | | - sourceObject?.let { |
36 | | - val getter = getters["${sourceObject.javaClass.name}.${fieldDefinition.name}"] |
37 | | - when { |
38 | | - getter != null -> getter.call(sourceObject) |
39 | | - else -> { |
40 | | - sourceObject::class.memberProperties |
41 | | - .find { it.name == fieldDefinition.name } |
42 | | - ?.let { kProperty -> |
43 | | - kProperty.getter.call(sourceObject).also { |
44 | | - register(sourceObject::class, kProperty) |
45 | | - } |
46 | | - } |
47 | | - } |
| 50 | + ): Any? { |
| 51 | + if (sourceObject == null) return null |
| 52 | + |
| 53 | + val getter = getters["${sourceObject.javaClass.name}.${fieldDefinition.name}"] |
| 54 | + if (getter != null) return getter.call(sourceObject) |
| 55 | + |
| 56 | + return sourceObject::class.memberProperties |
| 57 | + .find { it.name == fieldDefinition.name } |
| 58 | + ?.let { kProperty -> |
| 59 | + register(sourceObject::class, kProperty) |
| 60 | + return kProperty.getter.call(sourceObject) |
48 | 61 | } ?: run { |
49 | | - logger.error("getter method not found: ${sourceObject.javaClass.name}.${fieldDefinition.name}") |
50 | | - } |
| 62 | + logger.error("getter method not found: ${sourceObject.javaClass.name}.${fieldDefinition.name}") |
| 63 | + return null |
51 | 64 | } |
| 65 | + } |
52 | 66 |
|
53 | 67 | override fun get(environment: DataFetchingEnvironment): Any? = |
54 | | - environment.getSource<Any?>()?.let { sourceObject -> |
55 | | - getters["${sourceObject.javaClass.name}.${environment.fieldDefinition.name}"]?.call(sourceObject) |
56 | | - } |
| 68 | + get(environment.fieldDefinition, environment.getSource()) { environment } |
57 | 69 | } |
0 commit comments