All Downloads are FREE. Search and download functionalities are using the official Maven repository.

graphql.kickstart.tools.PropertyFieldResolver.kt Maven / Gradle / Ivy

There is a newer version: 14.0.0
Show newest version
package graphql.kickstart.tools

import graphql.language.FieldDefinition
import graphql.schema.DataFetcher
import graphql.schema.DataFetchingEnvironment
import java.lang.reflect.Field

/**
 * @author Andrew Potter
 */
internal class PropertyFieldResolver(field: FieldDefinition, search: FieldResolverScanner.Search, options: SchemaParserOptions, val property: Field): FieldResolver(field, search, options, property.declaringClass) {
    override fun createDataFetcher(): DataFetcher<*> {
        return PropertyFieldResolverDataFetcher(getSourceResolver(), property)
    }

    override fun scanForMatches(): List {
        return listOf(
                TypeClassMatcher.PotentialMatch.returnValue(
                    field.type,
                    property.genericType,
                    genericType,
                    SchemaClassScanner.FieldTypeReference(property.toString()),
                    false))
    }

    override fun toString() = "PropertyFieldResolver{property=$property}"
}

class PropertyFieldResolverDataFetcher(private val sourceResolver: SourceResolver, private val field: Field): DataFetcher {
    override fun get(environment: DataFetchingEnvironment): Any? {
        return field.get(sourceResolver(environment))
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy