Skip to content

Commit 6abf314

Browse files
authored
Merge pull request #560 from graphql-java-kickstart/renovate/major-graphql-java-(ignoring-snapshot-builds)
Update dependency com.graphql-java:graphql-java to v17
2 parents 89d7775 + 2af1235 commit 6abf314

File tree

9 files changed

+81
-53
lines changed

9 files changed

+81
-53
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<kotlin.version>1.5.0</kotlin.version>
1818
<kotlin-coroutines.version>1.5.0-native-mt</kotlin-coroutines.version>
1919
<jackson.version>2.12.4</jackson.version>
20-
<graphql-java.version>16.2</graphql-java.version>
20+
<graphql-java.version>17.0</graphql-java.version>
2121

2222
<maven.compiler.source>${java.version}</maven.compiler.source>
2323
<maven.compiler.target>${java.version}</maven.compiler.target>

src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class SchemaParser internal constructor(
319319
.build()
320320

321321

322-
output.add(schemaGeneratorHelper.buildDirective(directive, graphQLDirective, directiveLocation, runtimeWiring.comparatorRegistry))
322+
output.add(schemaGeneratorHelper.buildAppliedDirective(directive, graphQLDirective, directiveLocation, runtimeWiring.comparatorRegistry))
323323
}
324324
}
325325

src/main/kotlin/graphql/kickstart/tools/directive/SchemaDirectiveWiringEnvironmentImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/*
2525
* DO NOT EDIT THIS FILE!
2626
*
27-
* File copied from com.graphql-java.graphql-java:16.1 without any changes.
27+
* File copied from com.graphql-java.graphql-java:17.0 without any changes.
2828
*/
2929
@Internal
3030
public class SchemaDirectiveWiringEnvironmentImpl<T extends GraphQLDirectiveContainer> implements SchemaDirectiveWiringEnvironment<T> {

src/main/kotlin/graphql/kickstart/tools/directive/SchemaGeneratorDirectiveHelper.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.util.ArrayDeque;
2525
import java.util.Deque;
26+
import java.util.HashMap;
2627
import java.util.List;
2728
import java.util.Map;
2829

@@ -32,7 +33,7 @@
3233
/*
3334
* DO NOT EDIT THIS FILE!
3435
*
35-
* File copied from com.graphql-java.graphql-java:16.1 without changes except making the Parameters inner class public.
36+
* File copied from com.graphql-java.graphql-java:17.0 without changes except making the Parameters inner class public.
3637
*/
3738

3839
/**
@@ -43,6 +44,34 @@
4344
@Internal
4445
public class SchemaGeneratorDirectiveHelper {
4546

47+
/**
48+
* This will return true if something in the RuntimeWiring requires a {@link SchemaDirectiveWiring}. This is to allow
49+
* a shortcut to decide that that we dont need ANY SchemaDirectiveWiring post processing
50+
*
51+
* @param directiveContainer the element that has directives
52+
* @param typeRegistry the type registry
53+
* @param runtimeWiring the runtime wiring
54+
* @param <T> for two
55+
*
56+
* @return true if something in the RuntimeWiring requires a {@link SchemaDirectiveWiring}
57+
*/
58+
public static <T extends GraphQLDirectiveContainer> boolean schemaDirectiveWiringIsRequired(T directiveContainer, TypeDefinitionRegistry typeRegistry, RuntimeWiring runtimeWiring) {
59+
60+
WiringFactory wiringFactory = runtimeWiring.getWiringFactory();
61+
62+
Map<String, SchemaDirectiveWiring> registeredWiring = runtimeWiring.getRegisteredDirectiveWiring();
63+
List<SchemaDirectiveWiring> otherWiring = runtimeWiring.getDirectiveWiring();
64+
boolean thereAreSome = !registeredWiring.isEmpty() || !otherWiring.isEmpty();
65+
if (thereAreSome) {
66+
return true;
67+
}
68+
69+
Parameters params = new Parameters(typeRegistry, runtimeWiring, new HashMap<>(), null);
70+
SchemaDirectiveWiringEnvironment<T> env = new SchemaDirectiveWiringEnvironmentImpl<>(directiveContainer, directiveContainer.getDirectives(), null, params);
71+
// do they dynamically provide a wiring for this element?
72+
return wiringFactory.providesSchemaDirectiveWiring(env);
73+
}
74+
4675
public static class Parameters {
4776
private final TypeDefinitionRegistry typeRegistry;
4877
private final RuntimeWiring runtimeWiring;

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import graphql.introspection.Introspection
44
import graphql.language.Directive
55
import graphql.schema.GraphQLDirective
66
import graphql.schema.GraphqlTypeComparatorRegistry
7+
import graphql.schema.idl.RuntimeWiring.MOCKED_WIRING
8+
import graphql.schema.idl.SchemaGenerator.Options.defaultOptions
79

810
class SchemaGeneratorHelperExt : SchemaGeneratorHelper() {
911
// Re-expose a package protected method as public
10-
fun buildDirective(directive: Directive,
11-
graphQLDirective: GraphQLDirective,
12-
directiveLocation: Introspection.DirectiveLocation,
13-
comparatorRegistry: GraphqlTypeComparatorRegistry): GraphQLDirective {
14-
// Note 1: for now, it seems safe to pass buildCtx = null, since the code path where buildCtx is used,
15-
// is never called (directive.name == graphQLDirective.name is always true, see line with
16-
// directiveDefOpt = FpKit.findOne ...)
17-
// Note 2: repeatable directives (new feature in graphql-java 16) likely don't work,
12+
fun buildAppliedDirective(directive: Directive,
13+
graphQLDirective: GraphQLDirective,
14+
directiveLocation: Introspection.DirectiveLocation,
15+
comparatorRegistry: GraphqlTypeComparatorRegistry): GraphQLDirective {
16+
// Note: repeatable directives (new feature in graphql-java 16) likely don't work,
1817
// since we don't pass in the full set of discovered directives
19-
return super.buildDirective(null, directive, setOf(graphQLDirective), directiveLocation, comparatorRegistry)
18+
val context = BuildContext(TypeDefinitionRegistry(), MOCKED_WIRING, emptyMap(), defaultOptions())
19+
return super.buildAppliedDirective(context, directive, setOf(graphQLDirective), directiveLocation, comparatorRegistry)
2020
}
21-
}
21+
}

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,11 @@ val customScalarId = GraphQLScalarType.newScalar()
452452
else -> null
453453
}
454454

455-
override fun parseValue(input: Any): UUID? = parseLiteral(input)
455+
override fun parseValue(input: Any): UUID = parseLiteral(input)
456456

457-
override fun parseLiteral(input: Any): UUID? = when (input) {
457+
override fun parseLiteral(input: Any): UUID = when (input) {
458458
is StringValue -> UUID.fromString(input.value)
459-
else -> null
459+
else -> throw CoercingParseLiteralException()
460460
}
461461
})
462462
.build()
@@ -472,11 +472,11 @@ val customScalarUUID = GraphQLScalarType.newScalar()
472472
else -> null
473473
}
474474

475-
override fun parseValue(input: Any): UUID? = parseLiteral(input)
475+
override fun parseValue(input: Any): UUID = parseLiteral(input)
476476

477-
override fun parseLiteral(input: Any): UUID? = when (input) {
477+
override fun parseLiteral(input: Any): UUID = when (input) {
478478
is StringValue -> UUID.fromString(input.value)
479-
else -> null
479+
else -> throw CoercingParseLiteralException()
480480
}
481481
})
482482
.build()
@@ -487,12 +487,12 @@ val customScalarMap = GraphQLScalarType.newScalar()
487487
.coercing(object : Coercing<Map<String, Any>, Map<String, Any>> {
488488

489489
@Suppress("UNCHECKED_CAST")
490-
override fun parseValue(input: Any?): Map<String, Any> = input as Map<String, Any>
490+
override fun parseValue(input: Any): Map<String, Any> = input as Map<String, Any>
491491

492492
@Suppress("UNCHECKED_CAST")
493-
override fun serialize(dataFetcherResult: Any?): Map<String, Any> = dataFetcherResult as Map<String, Any>
493+
override fun serialize(dataFetcherResult: Any): Map<String, Any> = dataFetcherResult as Map<String, Any>
494494

495-
override fun parseLiteral(input: Any?): Map<String, Any> = (input as ObjectValue).objectFields.associateBy { it.name }.mapValues { (it.value.value as StringValue).value }
495+
override fun parseLiteral(input: Any): Map<String, Any> = (input as ObjectValue).objectFields.associateBy { it.name }.mapValues { (it.value.value as StringValue).value }
496496
})
497497
.build()
498498

@@ -505,21 +505,18 @@ val uploadScalar: GraphQLScalarType = GraphQLScalarType.newScalar()
505505
throw CoercingSerializeException("Upload is an input-only type")
506506
}
507507

508-
override fun parseValue(input: Any?): Part? {
508+
override fun parseValue(input: Any): Part {
509509
return when (input) {
510510
is Part -> {
511511
input
512512
}
513-
null -> {
514-
null
515-
}
516513
else -> {
517514
throw CoercingParseValueException("Expected type ${Part::class.java.name} but was ${input.javaClass.name}")
518515
}
519516
}
520517
}
521518

522-
override fun parseLiteral(input: Any): Part? {
519+
override fun parseLiteral(input: Any): Part {
523520
throw CoercingParseLiteralException(
524521
"Must use variables to specify Upload values")
525522
}

src/test/kotlin/graphql/kickstart/tools/MethodFieldResolverTest.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import graphql.ExecutionInput
44
import graphql.GraphQL
55
import graphql.language.StringValue
66
import graphql.schema.Coercing
7+
import graphql.schema.CoercingParseLiteralException
8+
import graphql.schema.CoercingSerializeException
79
import graphql.schema.GraphQLScalarType
810
import org.junit.Test
911
import java.lang.reflect.InvocationHandler
@@ -215,9 +217,9 @@ class MethodFieldResolverTest {
215217
val value get() = internalValue
216218

217219
companion object {
218-
fun of(input: Any?) = when (input) {
220+
fun of(input: Any) = when (input) {
219221
is String -> CustomScalar(input)
220-
else -> null
222+
else -> throw IllegalArgumentException()
221223
}
222224
}
223225
}
@@ -231,16 +233,16 @@ class MethodFieldResolverTest {
231233
.description("customScalar")
232234
.coercing(object : Coercing<CustomScalar, String> {
233235

234-
override fun parseValue(input: Any?) = CustomScalar.of(input)
236+
override fun parseValue(input: Any) = CustomScalar.of(input)
235237

236-
override fun parseLiteral(input: Any?) = when (input) {
238+
override fun parseLiteral(input: Any): CustomScalar = when (input) {
237239
is StringValue -> CustomScalar.of(input.value)
238-
else -> null
240+
else -> throw CoercingParseLiteralException()
239241
}
240242

241-
override fun serialize(dataFetcherResult: Any?) = when (dataFetcherResult) {
243+
override fun serialize(dataFetcherResult: Any) = when (dataFetcherResult) {
242244
is CustomScalar -> dataFetcherResult.value
243-
else -> null
245+
else -> throw CoercingSerializeException()
244246
}
245247
})
246248
.build()

src/test/kotlin/graphql/kickstart/tools/SchemaClassScannerTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ class SchemaClassScannerTest {
185185
.name("UUID")
186186
.description("Test scalars with duplicate types")
187187
.coercing(object : Coercing<Any, Any> {
188-
override fun serialize(dataFetcherResult: Any?): Any? = null
189-
override fun parseValue(input: Any?): Any? = null
190-
override fun parseLiteral(input: Any?): Any? = null
188+
override fun serialize(dataFetcherResult: Any): Any? = null
189+
override fun parseValue(input: Any): Any = input
190+
override fun parseLiteral(input: Any): Any = input
191191
}).build())
192192
.schemaString(
193193
"""
@@ -306,9 +306,9 @@ class SchemaClassScannerTest {
306306
val customMap = GraphQLScalarType.newScalar()
307307
.name("customMap")
308308
.coercing(object : Coercing<Map<String, Any>, Map<String, Any>> {
309-
override fun serialize(dataFetcherResult: Any?): Map<String, Any> = mapOf()
310-
override fun parseValue(input: Any?): Map<String, Any> = mapOf()
311-
override fun parseLiteral(input: Any?): Map<String, Any> = mapOf()
309+
override fun serialize(dataFetcherResult: Any): Map<String, Any> = mapOf()
310+
override fun parseValue(input: Any): Map<String, Any> = mapOf()
311+
override fun parseLiteral(input: Any): Map<String, Any> = mapOf()
312312
}).build()
313313

314314
val schema = SchemaParser.newParser()

src/test/resources/Place.graphqls

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ interface OtherPlace {
1818
reviews: [Review!]
1919
}
2020

21-
type Place1 implements Entity, Place, OtherPlace {
22-
id: ID!
23-
name: String
24-
other: String
25-
reviews: [Review1!]
26-
}
27-
28-
type Place2 implements Entity, Place, OtherPlace {
29-
id: ID!
30-
name: String
31-
other: String
32-
reviews: [Review2!]
21+
type Place1 implements Entity & Place & OtherPlace {
22+
id: ID!
23+
name: String
24+
other: String
25+
reviews: [Review1!]
26+
}
27+
28+
type Place2 implements Entity & Place & OtherPlace {
29+
id: ID!
30+
name: String
31+
other: String
32+
reviews: [Review2!]
3333
}
3434

3535
interface Review {

0 commit comments

Comments
 (0)