Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade graphql-java to 22.3 #788

Merged
merged 13 commits into from
Oct 8, 2024
20 changes: 11 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>13.1.2-SNAPSHOT</version>
<version>14.2.0-LOCAL</version>
oryan-block marked this conversation as resolved.
Show resolved Hide resolved
<packaging>jar</packaging>

<name>GraphQL Java Tools</name>
Expand All @@ -14,10 +14,10 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<kotlin.version>1.8.21</kotlin.version>
<kotlin-coroutines.version>1.7.3</kotlin-coroutines.version>
<jackson.version>2.16.0</jackson.version>
<graphql-java.version>21.3</graphql-java.version>
<kotlin.version>2.0.20</kotlin.version>
<kotlin-coroutines.version>1.9.0</kotlin-coroutines.version>
<jackson.version>2.17.0</jackson.version>
<graphql-java.version>22.3</graphql-java.version>
<reactive-streams.version>1.0.4</reactive-streams.version>

<maven.compiler.source>${java.version}</maven.compiler.source>
Expand Down Expand Up @@ -83,15 +83,15 @@
<version>3.29.2-GA</version>
<scope>provided</scope>
</dependency>
<!-- Optional for supporting spring proxies -->
<!-- Optional for supporting Spring proxies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.3.31</version>
<scope>provided</scope>
</dependency>

<!-- Test -->
<!-- Test -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
Expand Down Expand Up @@ -134,8 +134,8 @@
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<!--TODO remove this after upgrading kotlin-->
<exclusions>
<!-- kotlinx-coroutines-core-jvm brings more recent version -->
<exclusion>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
Expand Down Expand Up @@ -240,7 +240,8 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.5.0</version>
<!-- keep at 3.4.0 for JitPack to work -->
oryan-block marked this conversation as resolved.
Show resolved Hide resolved
<version>3.4.0</version>
<executions>
<execution>
<id>add-test-source</id>
Expand Down Expand Up @@ -306,6 +307,7 @@
<includes>
<include>**/*Test.*</include>
</includes>
<argLine>--add-reads kotlin.stdlib=kotlinx.coroutines.core</argLine>
oryan-block marked this conversation as resolved.
Show resolved Hide resolved
</configuration>
</plugin>
<plugin>
Expand Down
20 changes: 11 additions & 9 deletions src/main/kotlin/graphql/kickstart/tools/resolver/FieldResolver.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package graphql.kickstart.tools.resolver

import graphql.kickstart.tools.*
import graphql.kickstart.tools.GenericType
import graphql.kickstart.tools.ResolverError
import graphql.kickstart.tools.ResolverInfo
import graphql.kickstart.tools.TypeClassMatcher
import graphql.kickstart.tools.util.JavaType
import graphql.language.FieldDefinition
import graphql.schema.DataFetcher
Expand All @@ -29,12 +25,15 @@ internal abstract class FieldResolver(
/**
* Add source resolver depending on whether or not this is a resolver method
*/
protected fun getSourceResolver(): SourceResolver {
protected fun createSourceResolver(): SourceResolver {
return if (this.search.source != null) {
{ this.search.source }
SourceResolver { _, _ -> this.search.source }
} else {
{ environment ->
val source = environment.getSource<Any>()
SourceResolver { environment, sourceObject ->
// if source object is known, environment is null as an optimization (LightDataFetcher)
val source = sourceObject
?: environment?.getSource<Any>()
?: throw ResolverError("Expected DataFetchingEnvironment and source object to not be null!")

if (!this.genericType.isAssignableFrom(source.javaClass)) {
throw ResolverError("Expected source object to be an instance of '${this.genericType.getRawClass().name}' but instead got '${source.javaClass.name}'")
Expand All @@ -46,4 +45,7 @@ internal abstract class FieldResolver(
}
}

internal typealias SourceResolver = (DataFetchingEnvironment) -> Any
fun interface SourceResolver {

fun resolve(environment: DataFetchingEnvironment?, source: Any?): Any
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import graphql.kickstart.tools.util.JavaType
import graphql.language.FieldDefinition
import graphql.schema.DataFetcher
import graphql.schema.DataFetchingEnvironment
import graphql.schema.GraphQLFieldDefinition
import graphql.schema.LightDataFetcher
import java.util.function.Supplier

/**
* @author Nick Weedon
Expand Down Expand Up @@ -37,7 +40,7 @@ internal class MapFieldResolver(
}

override fun createDataFetcher(): DataFetcher<*> {
return MapFieldResolverDataFetcher(getSourceResolver(), field.name)
return MapFieldResolverDataFetcher(createSourceResolver(), field.name)
}

override fun scanForMatches(): List<TypeClassMatcher.PotentialMatch> {
Expand All @@ -50,14 +53,17 @@ internal class MapFieldResolver(
internal class MapFieldResolverDataFetcher(
private val sourceResolver: SourceResolver,
private val key: String
) : DataFetcher<Any> {
) : LightDataFetcher<Any> {

override fun get(environment: DataFetchingEnvironment): Any? {
val resolvedSourceObject = sourceResolver(environment)
if (resolvedSourceObject is Map<*, *>) {
return resolvedSourceObject[key]
override fun get(fieldDefinition: GraphQLFieldDefinition, sourceObject: Any?, environmentSupplier: Supplier<DataFetchingEnvironment>): Any? {
if (sourceObject is Map<*, *>) {
return sourceObject[key]
} else {
throw RuntimeException("MapFieldResolver attempt to fetch a field from an object instance that was not a map")
}
}

override fun get(environment: DataFetchingEnvironment): Any? {
return get(environment.fieldDefinition, sourceResolver.resolve(environment, null)) { environment }
}
}
Loading