Skip to content

Commit 6370189

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 5ad0758 + fbb16ac commit 6370189

File tree

7 files changed

+46
-26
lines changed

7 files changed

+46
-26
lines changed

pom.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<dependency>
4949
<groupId>com.graphql-java</groupId>
5050
<artifactId>graphql-java</artifactId>
51-
<version>11.0</version>
51+
<version>12.0</version>
5252
</dependency>
5353
<dependency>
5454
<groupId>com.fasterxml</groupId>
@@ -217,6 +217,7 @@
217217
<plugin>
218218
<groupId>org.apache.maven.plugins</groupId>
219219
<artifactId>maven-jar-plugin</artifactId>
220+
<version>3.1.1</version>
220221
<executions>
221222
<execution>
222223
<id>test-jar</id>

src/main/kotlin/com/coxautodev/graphql/tools/RootTypeInfo.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ internal class RootTypeInfo private constructor(val queryType: TypeName?, val mu
1313
const val DEFAULT_SUBSCRIPTION_NAME = "Subscription"
1414

1515
fun fromSchemaDefinitions(definitions: List<SchemaDefinition>): RootTypeInfo {
16-
val queryType = definitions.lastOrNull()?.operationTypeDefinitions?.find { it.name == "query" }?.type as TypeName?
17-
val mutationType = definitions.lastOrNull()?.operationTypeDefinitions?.find { it.name == "mutation" }?.type as TypeName?
18-
val subscriptionType = definitions.lastOrNull()?.operationTypeDefinitions?.find { it.name == "subscription" }?.type as TypeName?
16+
val queryType = definitions.lastOrNull()?.operationTypeDefinitions?.find { it.name == "query" }?.typeName
17+
val mutationType = definitions.lastOrNull()?.operationTypeDefinitions?.find { it.name == "mutation" }?.typeName
18+
val subscriptionType = definitions.lastOrNull()?.operationTypeDefinitions?.find { it.name == "subscription" }?.typeName
1919

2020
return RootTypeInfo(queryType, mutationType, subscriptionType)
2121
}

src/main/kotlin/com/coxautodev/graphql/tools/SchemaParser.kt

+22-7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import graphql.schema.idl.ScalarInfo
4747
import graphql.schema.idl.SchemaGeneratorHelper
4848
import java.util.*
4949
import kotlin.reflect.KClass
50+
import kotlin.reflect.full.memberProperties
51+
import kotlin.reflect.jvm.isAccessible
5052

5153
/**
5254
* Parses a GraphQL Schema and maps object fields to provided class methods.
@@ -105,9 +107,16 @@ class SchemaParser internal constructor(scanResult: ScannedSchemaObjects, privat
105107
val inputObjects = inputObjectDefinitions.map { createInputObject(it) }
106108
val enums = enumDefinitions.map { createEnumObject(it) }
107109

110+
// Unfortunately, since graphql-java 12, the getTypeResolver method has been made package-protected,
111+
// so we need reflection to access the 'typeResolver' field on GraphQLInterfaceType and GraphQLUnionType
112+
val interfaceTypeResolverField = GraphQLInterfaceType::class.memberProperties.find { it.name == "typeResolver" }
113+
interfaceTypeResolverField!!.isAccessible = true
114+
val unionTypeResolverField = GraphQLUnionType::class.memberProperties.find { it.name == "typeResolver" }
115+
unionTypeResolverField!!.isAccessible = true
116+
108117
// Assign type resolver to interfaces now that we know all of the object types
109-
interfaces.forEach { (it.typeResolver as TypeResolverProxy).typeResolver = InterfaceTypeResolver(dictionary.inverse(), it, objects) }
110-
unions.forEach { (it.typeResolver as TypeResolverProxy).typeResolver = UnionTypeResolver(dictionary.inverse(), it, objects) }
118+
interfaces.forEach { (interfaceTypeResolverField.get(it) as TypeResolverProxy).typeResolver = InterfaceTypeResolver(dictionary.inverse(), it, objects) }
119+
unions.forEach { (unionTypeResolverField.get(it) as TypeResolverProxy).typeResolver = UnionTypeResolver(dictionary.inverse(), it, objects) }
111120

112121
// Find query type and mutation/subscription type (if mutation/subscription type exists)
113122
val queryName = rootInfo.getQueryName()
@@ -159,7 +168,7 @@ class SchemaParser internal constructor(scanResult: ScannedSchemaObjects, privat
159168
val wiredField = directiveGenerator.onField(field.build(), DirectiveBehavior.Params(runtimeWiring))
160169
GraphQLFieldDefinition.Builder(wiredField)
161170
.clearArguments()
162-
.argument(wiredField.arguments)
171+
.arguments(wiredField.arguments)
163172
}
164173
}
165174

@@ -219,11 +228,17 @@ class SchemaParser internal constructor(scanResult: ScannedSchemaObjects, privat
219228
val enumName = enumDefinition.name
220229
val enumValue = type.unwrap().enumConstants.find { (it as Enum<*>).name == enumName }
221230
?: throw SchemaError("Expected value for name '$enumName' in enum '${type.unwrap().simpleName}' but found none!")
222-
val enumValueDirectives = buildDirectives(enumDefinition.directives, setOf(), Introspection.DirectiveLocation.ENUM_VALUE).toMutableList()
231+
val enumValueDirectives = buildDirectives(enumDefinition.directives, setOf(), Introspection.DirectiveLocation.ENUM_VALUE)
223232
getDeprecated(enumDefinition.directives).let {
224-
val enumValueDefinition = GraphQLEnumValueDefinition(enumName,
225-
if (enumDefinition.description != null) enumDefinition.description.content else getDocumentation(enumDefinition),
226-
enumValue, it, enumValueDirectives)
233+
val enumValueDefinition = GraphQLEnumValueDefinition.newEnumValueDefinition()
234+
.name(enumName)
235+
.description(if (enumDefinition.description != null) enumDefinition.description.content else getDocumentation(enumDefinition))
236+
.value(enumValue)
237+
.deprecationReason(it)
238+
.withDirectives(*enumValueDirectives)
239+
.definition(enumDefinition)
240+
.build()
241+
227242
builder.value(directiveGenerator.onEnumValue(enumValueDefinition, DirectiveBehavior.Params(runtimeWiring)))
228243
}
229244
}

src/main/kotlin/com/coxautodev/graphql/tools/relay/RelayConnectionFactory.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import graphql.language.Comment
66
import graphql.language.Definition
77
import graphql.language.Directive
88
import graphql.language.FieldDefinition
9+
import graphql.language.IgnoredChars
910
import graphql.language.ListType
1011
import graphql.language.NonNullType
1112
import graphql.language.ObjectTypeDefinition
@@ -87,7 +88,7 @@ class RelayConnectionFactory : TypeDefinitionFactory {
8788
return this.directives.map { it.withField(this) }
8889
}
8990

90-
class DirectiveWithField(val field: FieldDefinition, name: String, arguments: List<Argument>, sourceLocation: SourceLocation, comments: List<Comment>) : Directive(name, arguments, sourceLocation, comments) {
91+
class DirectiveWithField(val field: FieldDefinition, name: String, arguments: List<Argument>, sourceLocation: SourceLocation, comments: List<Comment>) : Directive(name, arguments, sourceLocation, comments, IgnoredChars.EMPTY) {
9192
fun getTypeName(): String {
9293
val type = field.type
9394
if (type is NonNullType) {

src/main/kotlin/graphql/schema/idl/DirectiveBehavior.kt

+14-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class DirectiveBehavior {
2020
}
2121

2222
fun onField(element: GraphQLFieldDefinition, params: Params): GraphQLFieldDefinition {
23-
return directiveHelper.onField(element, params.toParameters())
23+
// noop, since the actual behaviour has moved to onObject/onInterface since graphql-java 12.0
24+
return element
2425
}
2526

2627
fun onInterface(element: GraphQLInterfaceType, params: Params): GraphQLInterfaceType =
@@ -35,17 +36,23 @@ class DirectiveBehavior {
3536
fun onEnum(element: GraphQLEnumType, params: Params): GraphQLEnumType =
3637
directiveHelper.onEnum(element, params.toParameters())
3738

38-
fun onEnumValue(element: GraphQLEnumValueDefinition, params: Params): GraphQLEnumValueDefinition =
39-
directiveHelper.onEnumValue(element, params.toParameters())
39+
fun onEnumValue(element: GraphQLEnumValueDefinition, params: Params): GraphQLEnumValueDefinition {
40+
// noop, since the actual behaviour has moved to onEnum since graphql-java 12.0
41+
return element
42+
}
4043

41-
fun onArgument(element: GraphQLArgument, params: Params): GraphQLArgument =
42-
directiveHelper.onArgument(element, params.toParameters())
44+
fun onArgument(element: GraphQLArgument, params: Params): GraphQLArgument {
45+
// noop, since the actual behaviour has moved to onObject/onInterface since graphql-java 12.0
46+
return element
47+
}
4348

4449
fun onInputObject(element: GraphQLInputObjectType, params: Params): GraphQLInputObjectType =
4550
directiveHelper.onInputObjectType(element, params.toParameters())
4651

47-
fun onInputObjectField(element: GraphQLInputObjectField, params: Params): GraphQLInputObjectField =
48-
directiveHelper.onInputObjectField(element, params.toParameters())
52+
fun onInputObjectField(element: GraphQLInputObjectField, params: Params): GraphQLInputObjectField {
53+
// noop, since the actual behaviour has moved to onInputObjectType since graphql-java 12.0
54+
return element
55+
}
4956

5057
data class Params(val runtimeWiring: RuntimeWiring) {
5158
internal fun toParameters() = SchemaGeneratorDirectiveHelper.Parameters(null, runtimeWiring, null, null)

src/test/groovy/com/coxautodev/graphql/tools/MethodFieldResolverDataFetcherSpec.groovy

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ import graphql.execution.ExecutionId
88
import graphql.execution.ExecutionStrategy
99
import graphql.execution.ExecutionStrategyParameters
1010
import graphql.execution.instrumentation.SimpleInstrumentation
11-
import graphql.language.BooleanValue
1211
import graphql.language.FieldDefinition
1312
import graphql.language.InputValueDefinition
1413
import graphql.language.NonNullType
1514
import graphql.language.TypeName
1615
import graphql.schema.DataFetcher
1716
import graphql.schema.DataFetchingEnvironment
18-
import graphql.schema.DataFetchingEnvironmentBuilder
1917
import graphql.schema.DataFetchingEnvironmentImpl
2018
import spock.lang.Specification
2119

@@ -213,11 +211,10 @@ class MethodFieldResolverDataFetcherSpec extends Specification {
213211
}
214212
215213
private static DataFetchingEnvironment createEnvironment(Object context, Object source, Map<String, Object> arguments = [:]) {
216-
DataFetchingEnvironmentBuilder.newDataFetchingEnvironment()
214+
DataFetchingEnvironmentImpl.newDataFetchingEnvironment(buildExecutionContext())
217215
.source(source)
218216
.arguments(arguments)
219217
.context(context)
220-
.executionContext(buildExecutionContext())
221218
.build()
222219
}
223220

src/test/kotlin/com/coxautodev/graphql/tools/MethodFieldResolverDataFetcherTest.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import graphql.language.InputValueDefinition
88
import graphql.language.TypeName
99
import graphql.schema.DataFetcher
1010
import graphql.schema.DataFetchingEnvironment
11-
import graphql.schema.DataFetchingEnvironmentBuilder
11+
import graphql.schema.DataFetchingEnvironmentImpl
1212
import kotlinx.coroutines.Dispatchers
1313
import kotlinx.coroutines.ExperimentalCoroutinesApi
1414
import kotlinx.coroutines.Job
@@ -108,11 +108,10 @@ class MethodFieldResolverDataFetcherTest {
108108
}
109109

110110
private fun createEnvironment(source: Any, arguments: Map<String, Any> = emptyMap(), context: Any? = null): DataFetchingEnvironment {
111-
return DataFetchingEnvironmentBuilder.newDataFetchingEnvironment()
111+
return DataFetchingEnvironmentImpl.newDataFetchingEnvironment(buildExecutionContext())
112112
.source(source)
113113
.arguments(arguments)
114114
.context(context)
115-
.executionContext(buildExecutionContext())
116115
.build()
117116
}
118117

0 commit comments

Comments
 (0)