Skip to content

Commit 8b6971f

Browse files
authoredJul 28, 2023
Merge pull request #754 from graphql-java-kickstart/renovate/major-graphql-java.version
Update dependency com.graphql-java:graphql-java to v21
2 parents cccbd2f + c0e533d commit 8b6971f

19 files changed

+114
-69
lines changed
 

‎.github/workflows/pull-request.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
java: [ '8', '11', '15' ]
10+
java: [ '11', '15', '17' ]
1111
steps:
1212
- name: Checkout
1313
uses: actions/checkout@v3

‎.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
- name: Setup java
1010
uses: actions/setup-java@v3
1111
with:
12-
java-version: '8'
12+
java-version: '11'
1313
distribution: 'adopt'
1414
- name: Build with Maven
1515
run: mvn --batch-mode --update-snapshots verify
@@ -23,7 +23,7 @@ jobs:
2323
- name: Setup Maven Central
2424
uses: actions/setup-java@v3
2525
with:
26-
java-version: '8'
26+
java-version: '11'
2727
distribution: 'adopt'
2828
server-id: ossrh
2929
server-username: MAVEN_USERNAME

‎.github/workflows/snapshot.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Setup java
1313
uses: actions/setup-java@v3
1414
with:
15-
java-version: '8'
15+
java-version: '11'
1616
distribution: 'adopt'
1717
- name: Build with Maven
1818
run: mvn --batch-mode --update-snapshots verify
@@ -26,7 +26,7 @@ jobs:
2626
- name: Setup Maven Central
2727
uses: actions/setup-java@v3
2828
with:
29-
java-version: '8'
29+
java-version: '11'
3030
distribution: 'adopt'
3131
server-id: ossrh
3232
server-username: MAVEN_USERNAME

‎pom.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
<properties>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16-
<java.version>1.8</java.version>
16+
<java.version>11</java.version>
1717
<kotlin.version>1.8.21</kotlin.version>
1818
<kotlin-coroutines.version>1.6.4</kotlin-coroutines.version>
1919
<jackson.version>2.14.2</jackson.version>
20-
<graphql-java.version>20.1</graphql-java.version>
20+
<graphql-java.version>21.0</graphql-java.version>
2121
<reactive-streams.version>1.0.4</reactive-streams.version>
2222

2323
<maven.compiler.source>${java.version}</maven.compiler.source>
@@ -279,8 +279,8 @@
279279
<artifactId>maven-compiler-plugin</artifactId>
280280
<version>3.11.0</version>
281281
<configuration>
282-
<source>1.8</source>
283-
<target>1.8</target>
282+
<source>11</source>
283+
<target>11</target>
284284
</configuration>
285285
</plugin>
286286

‎src/main/kotlin/graphql/kickstart/tools/GenericType.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ internal open class GenericType(protected val mostSpecificType: JavaType, protec
8383
* Unwrap certain Java types to find the "real" class.
8484
*/
8585
fun unwrapGenericType(javaType: JavaType): JavaType {
86-
val type = replaceTypeVariable(javaType)
87-
return when (type) {
86+
return when (val type = replaceTypeVariable(javaType)) {
8887
is ParameterizedType -> {
8988
val rawType = type.rawType
9089
val genericType = options.genericWrappers.find { it.type == rawType }
@@ -107,7 +106,7 @@ internal open class GenericType(protected val mostSpecificType: JavaType, protec
107106
}
108107
}
109108
is WildcardType -> type.upperBounds.firstOrNull()
110-
?: throw error("Unable to unwrap type, wildcard has no upper bound: $type")
109+
?: error("Unable to unwrap type, wildcard has no upper bound: $type")
111110
is Class<*> -> if (type.isPrimitive) Primitives.wrap(type) else type
112111
else -> error("Unable to unwrap type: $type")
113112
}

‎src/main/kotlin/graphql/kickstart/tools/SchemaClassScanner.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ internal class SchemaClassScanner(
174174
.coercing(provided.coercing)
175175
.definition(definition)
176176
.build()
177-
}.associateBy { it.name!! }
177+
}.associateBy { it.name }
178178

179179
val unusedDefinitions = (definitionsByName.values - observedDefinitions).toSet()
180180
unusedDefinitions

‎src/main/kotlin/graphql/kickstart/tools/SchemaParserBuilder.kt

+28-19
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import graphql.language.Definition
44
import graphql.language.Document
55
import graphql.parser.MultiSourceReader
66
import graphql.parser.Parser
7+
import graphql.parser.ParserEnvironment
78
import graphql.parser.ParserOptions
89
import graphql.schema.GraphQLScalarType
910
import graphql.schema.idl.RuntimeWiring
@@ -25,6 +26,10 @@ class SchemaParserBuilder {
2526
private val scalars = mutableListOf<GraphQLScalarType>()
2627
private val runtimeWiringBuilder = RuntimeWiring.newRuntimeWiring()
2728
private var options = SchemaParserOptions.defaultOptions()
29+
private val parser = Parser()
30+
private val parserOptions = ParserOptions
31+
.getDefaultParserOptions()
32+
.transform { o -> o.maxTokens(MAX_VALUE) }
2833

2934
/**
3035
* Add GraphQL schema files from the classpath.
@@ -166,21 +171,14 @@ class SchemaParserBuilder {
166171
}
167172

168173
private fun parseDocuments(): List<Document> {
169-
val parser = Parser()
170-
val documents = mutableListOf<Document>()
171174
try {
172-
val options = ParserOptions
173-
.getDefaultParserOptions()
174-
.transform { o -> o.maxTokens(MAX_VALUE) }
175+
val documents = files.map { parseDocument(readFile(it), it) }.toMutableList()
175176

176-
files.forEach {
177-
val sourceReader = MultiSourceReader.newMultiSourceReader().string(readFile(it), it).trackData(true).build()
178-
documents.add(parser.parseDocument(sourceReader, options))
177+
if (schemaString.isNotBlank()) {
178+
documents.add(parseDocument(schemaString.toString()))
179179
}
180180

181-
if (schemaString.isNotEmpty()) {
182-
documents.add(parser.parseDocument(schemaString.toString(), options))
183-
}
181+
return documents
184182
} catch (pce: ParseCancellationException) {
185183
val cause = pce.cause
186184
if (cause != null && cause is RecognitionException) {
@@ -189,23 +187,34 @@ class SchemaParserBuilder {
189187
throw pce
190188
}
191189
}
192-
return documents
193190
}
194191

195-
private fun readFile(filename: String): String {
196-
return java.io.BufferedReader(java.io.InputStreamReader(
197-
object : Any() {}.javaClass.classLoader.getResourceAsStream(filename)
198-
?: throw java.io.FileNotFoundException("classpath:$filename")
199-
)).readText()
192+
private fun parseDocument(input: String, sourceName: String? = null): Document {
193+
val sourceReader = MultiSourceReader
194+
.newMultiSourceReader()
195+
.string(input, sourceName)
196+
.trackData(true).build()
197+
val environment = ParserEnvironment
198+
.newParserEnvironment()
199+
.document(sourceReader)
200+
.parserOptions(parserOptions).build()
201+
return parser.parseDocument(environment)
200202
}
201203

204+
private fun readFile(filename: String) =
205+
this::class.java.classLoader.getResource(filename)?.readText()
206+
?: throw java.io.FileNotFoundException("classpath:$filename")
207+
202208
/**
203209
* Build the parser with the supplied schema and dictionary.
204210
*/
205211
fun build() = SchemaParser(scan(), options, runtimeWiringBuilder.build())
206212
}
207213

208-
class InvalidSchemaError(pce: ParseCancellationException, private val recognitionException: RecognitionException) : RuntimeException(pce) {
209-
override val message: String?
214+
class InvalidSchemaError(
215+
pce: ParseCancellationException,
216+
private val recognitionException: RecognitionException
217+
) : RuntimeException(pce) {
218+
override val message: String
210219
get() = "Invalid schema provided (${recognitionException.javaClass.name}) at: ${recognitionException.offendingToken}"
211220
}

‎src/main/kotlin/graphql/kickstart/tools/TypeClassMatcher.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ internal class TypeClassMatcher(private val definitionsByName: Map<String, TypeD
6868
is ListType -> {
6969
if (realType is ParameterizedType && isListType(realType, potentialMatch)) {
7070
match(potentialMatch, graphQLType.type, realType.actualTypeArguments.first())
71-
} else if ((realType as Class<*>).isArray) {
71+
} else if (realType is Class<*> && realType.isArray) {
7272
match(potentialMatch, graphQLType.type, realType.componentType)
7373
} else {
7474
throw error(potentialMatch, "Java class is not a List or generic type information was lost: $realType")

‎src/main/kotlin/graphql/kickstart/tools/directive/SchemaDirectiveWiringEnvironmentImpl.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class SchemaDirectiveWiringEnvironmentImpl<T : GraphQLDirectiveContainer?>(
5656
override fun getFieldDataFetcher(): DataFetcher<*> {
5757
checkNotNull(fieldDefinition) { "An output field must be in context to call this method" }
5858
checkNotNull(fieldsContainer) { "An output field container must be in context to call this method" }
59-
return codeRegistry.getDataFetcher(fieldsContainer, fieldDefinition)
59+
val coordinates = FieldCoordinates.coordinates(fieldsContainer, fieldDefinition)
60+
return codeRegistry.getDataFetcher(coordinates, fieldDefinition)
6061
}
6162

6263
override fun setFieldDataFetcher(newDataFetcher: DataFetcher<*>?): GraphQLFieldDefinition {

‎src/test/kotlin/graphql/kickstart/tools/DirectiveTest.kt

+4-7
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import graphql.GraphQL
44
import graphql.execution.AsyncExecutionStrategy
55
import graphql.relay.Connection
66
import graphql.relay.SimpleListConnection
7-
import graphql.schema.DataFetcherFactories
8-
import graphql.schema.DataFetchingEnvironment
9-
import graphql.schema.GraphQLFieldDefinition
10-
import graphql.schema.GraphQLObjectType
7+
import graphql.schema.*
118
import graphql.schema.idl.SchemaDirectiveWiring
129
import graphql.schema.idl.SchemaDirectiveWiringEnvironment
1310
import org.junit.Ignore
@@ -325,7 +322,7 @@ class DirectiveTest {
325322

326323
override fun onField(environment: SchemaDirectiveWiringEnvironment<GraphQLFieldDefinition>): GraphQLFieldDefinition {
327324
val field = environment.element
328-
val parentType = environment.fieldsContainer
325+
val parentType = FieldCoordinates.coordinates(environment.fieldsContainer, environment.fieldDefinition)
329326

330327
val originalDataFetcher = environment.codeRegistry.getDataFetcher(parentType, field)
331328
val wrappedDataFetcher = DataFetcherFactories.wrapDataFetcher(originalDataFetcher) { _, value ->
@@ -342,15 +339,15 @@ class DirectiveTest {
342339

343340
override fun onField(environment: SchemaDirectiveWiringEnvironment<GraphQLFieldDefinition>): GraphQLFieldDefinition {
344341
val field = environment.element
345-
val parentType = environment.fieldsContainer
342+
val parentType = FieldCoordinates.coordinates(environment.fieldsContainer, environment.fieldDefinition)
346343

347344
val originalDataFetcher = environment.codeRegistry.getDataFetcher(parentType, field)
348345
val wrappedDataFetcher = DataFetcherFactories.wrapDataFetcher(originalDataFetcher) { _, value ->
349346
val string = value as? String
350347
string + string
351348
}
352349

353-
environment.codeRegistry.dataFetcher(parentType, field, wrappedDataFetcher)
350+
environment.codeRegistry.dataFetcher(parentType, wrappedDataFetcher)
354351

355352
return field
356353
}

‎src/test/kotlin/graphql/kickstart/tools/EndToEndSpecHelper.kt

+34-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package graphql.kickstart.tools
22

3+
import graphql.GraphQLContext
4+
import graphql.execution.CoercedVariables
35
import graphql.execution.DataFetcherResult
46
import graphql.language.ObjectValue
57
import graphql.language.StringValue
8+
import graphql.language.Value
69
import graphql.schema.*
710
import kotlinx.coroutines.CompletableDeferred
811
import kotlinx.coroutines.channels.Channel
@@ -444,18 +447,22 @@ val customScalarId = GraphQLScalarType.newScalar()
444447
.name("ID")
445448
.description("Overrides built-in ID")
446449
.coercing(object : Coercing<UUID, String> {
447-
override fun serialize(input: Any): String? = when (input) {
450+
override fun serialize(input: Any, context: GraphQLContext, locale: Locale) = when (input) {
448451
is String -> input
449452
is UUID -> input.toString()
450453
else -> null
451454
}
452455

453-
override fun parseValue(input: Any): UUID = parseLiteral(input)
454-
455-
override fun parseLiteral(input: Any): UUID = when (input) {
456+
override fun parseValue(input: Any, context: GraphQLContext, locale: Locale) = when (input) {
456457
is StringValue -> UUID.fromString(input.value)
457458
else -> throw CoercingParseLiteralException()
458459
}
460+
461+
override fun parseLiteral(input: Value<*>, variables: CoercedVariables, context: GraphQLContext, locale: Locale) =
462+
when (input) {
463+
is StringValue -> UUID.fromString(input.value)
464+
else -> throw CoercingParseLiteralException()
465+
}
459466
})
460467
.build()
461468

@@ -464,18 +471,22 @@ val customScalarUUID = GraphQLScalarType.newScalar()
464471
.description("UUID")
465472
.coercing(object : Coercing<UUID, String> {
466473

467-
override fun serialize(input: Any): String? = when (input) {
474+
override fun serialize(input: Any, context: GraphQLContext, locale: Locale): String? = when (input) {
468475
is String -> input
469476
is UUID -> input.toString()
470477
else -> null
471478
}
472479

473-
override fun parseValue(input: Any): UUID = parseLiteral(input)
474-
475-
override fun parseLiteral(input: Any): UUID = when (input) {
480+
override fun parseValue(input: Any, context: GraphQLContext, locale: Locale): UUID = when (input) {
476481
is StringValue -> UUID.fromString(input.value)
477482
else -> throw CoercingParseLiteralException()
478483
}
484+
485+
override fun parseLiteral(input: Value<*>, variables: CoercedVariables, context: GraphQLContext, locale: Locale): UUID =
486+
when (input) {
487+
is StringValue -> UUID.fromString(input.value)
488+
else -> throw CoercingParseLiteralException()
489+
}
479490
})
480491
.build()
481492

@@ -485,12 +496,19 @@ val customScalarMap = GraphQLScalarType.newScalar()
485496
.coercing(object : Coercing<Map<String, Any>, Map<String, Any>> {
486497

487498
@Suppress("UNCHECKED_CAST")
488-
override fun parseValue(input: Any): Map<String, Any> = input as Map<String, Any>
499+
override fun parseValue(input: Any, context: GraphQLContext, locale: Locale): Map<String, Any> = input as Map<String, Any>
489500

490501
@Suppress("UNCHECKED_CAST")
491-
override fun serialize(dataFetcherResult: Any): Map<String, Any> = dataFetcherResult as Map<String, Any>
492-
493-
override fun parseLiteral(input: Any): Map<String, Any> = (input as ObjectValue).objectFields.associateBy { it.name }.mapValues { (it.value.value as StringValue).value }
502+
override fun serialize(dataFetcherResult: Any, context: GraphQLContext, locale: Locale): Map<String, Any> =
503+
dataFetcherResult as Map<String, Any>
504+
505+
override fun parseLiteral(
506+
input: Value<*>,
507+
variables: CoercedVariables,
508+
context: GraphQLContext,
509+
locale: Locale
510+
): Map<String, Any> =
511+
(input as ObjectValue).objectFields.associateBy { it.name }.mapValues { (it.value.value as StringValue).value }
494512
})
495513
.build()
496514

@@ -499,11 +517,11 @@ val uploadScalar: GraphQLScalarType = GraphQLScalarType.newScalar()
499517
.name("Upload")
500518
.description("A file part in a multipart request")
501519
.coercing(object : Coercing<Part?, Void?> {
502-
override fun serialize(dataFetcherResult: Any): Void? {
520+
override fun serialize(dataFetcherResult: Any, context: GraphQLContext, locale: Locale): Void? {
503521
throw CoercingSerializeException("Upload is an input-only type")
504522
}
505523

506-
override fun parseValue(input: Any): Part {
524+
override fun parseValue(input: Any, context: GraphQLContext, locale: Locale): Part {
507525
return when (input) {
508526
is Part -> {
509527
input
@@ -514,9 +532,8 @@ val uploadScalar: GraphQLScalarType = GraphQLScalarType.newScalar()
514532
}
515533
}
516534

517-
override fun parseLiteral(input: Any): Part {
518-
throw CoercingParseLiteralException(
519-
"Must use variables to specify Upload values")
535+
override fun parseLiteral(input: Value<*>, variables: CoercedVariables, context: GraphQLContext, locale: Locale): Part {
536+
throw CoercingParseLiteralException("Must use variables to specify Upload values")
520537
}
521538
}).build()
522539

‎src/test/kotlin/graphql/kickstart/tools/FieldResolverScannerTest.kt

+2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import graphql.language.TypeName
1010
import graphql.relay.Connection
1111
import graphql.relay.DefaultConnection
1212
import graphql.relay.DefaultPageInfo
13+
import kotlinx.coroutines.ExperimentalCoroutinesApi
1314
import org.junit.Test
1415
import java.util.*
1516

17+
@OptIn(ExperimentalCoroutinesApi::class)
1618
class FieldResolverScannerTest {
1719

1820
private val options = defaultOptions()

‎src/test/kotlin/graphql/kickstart/tools/MethodFieldResolverDataFetcherTest.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package graphql.kickstart.tools
33
import graphql.ExecutionResult
44
import graphql.GraphQLContext
55
import graphql.execution.*
6-
import graphql.execution.instrumentation.SimpleInstrumentation
6+
import graphql.execution.instrumentation.SimplePerformantInstrumentation
77
import graphql.kickstart.tools.resolver.FieldResolverError
88
import graphql.kickstart.tools.resolver.FieldResolverScanner
99
import graphql.language.FieldDefinition
@@ -24,6 +24,7 @@ import org.reactivestreams.tck.TestEnvironment
2424
import java.util.concurrent.CompletableFuture
2525
import kotlin.coroutines.coroutineContext
2626

27+
@OptIn(ExperimentalCoroutinesApi::class)
2728
class MethodFieldResolverDataFetcherTest {
2829

2930
@Test
@@ -311,7 +312,7 @@ class MethodFieldResolverDataFetcherTest {
311312
}
312313
val executionId = ExecutionId.from("executionId123")
313314
return ExecutionContextBuilder.newExecutionContextBuilder()
314-
.instrumentation(SimpleInstrumentation.INSTANCE)
315+
.instrumentation(SimplePerformantInstrumentation.INSTANCE)
315316
.executionId(executionId)
316317
.queryStrategy(executionStrategy)
317318
.mutationStrategy(executionStrategy)

0 commit comments

Comments
 (0)
Please sign in to comment.