From fdf3345b54c2a3c9a699b93b83a28b5ab0f1f0f8 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 3 Aug 2021 13:05:27 +0000 Subject: [PATCH 1/2] Update dependency com.graphql-java:graphql-java to v17 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 39ece232..f774f703 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ 1.5.0 1.5.0-native-mt 2.12.4 - 16.2 + 17.0 ${java.version} ${java.version} From f1adcd99c156c6978536b2605961ce76b2d8050c Mon Sep 17 00:00:00 2001 From: Oryan M Date: Wed, 4 Aug 2021 15:02:12 -0400 Subject: [PATCH 2/2] Fix breaking changes after update --- .../graphql/kickstart/tools/SchemaParser.kt | 2 +- .../SchemaDirectiveWiringEnvironmentImpl.java | 2 +- .../SchemaGeneratorDirectiveHelper.java | 31 ++++++++++++++++++- .../schema/idl/SchemaGeneratorHelperExt.kt | 20 ++++++------ .../kickstart/tools/EndToEndSpecHelper.kt | 25 +++++++-------- .../tools/MethodFieldResolverTest.kt | 16 +++++----- .../kickstart/tools/SchemaClassScannerTest.kt | 12 +++---- src/test/resources/Place.graphqls | 24 +++++++------- 8 files changed, 80 insertions(+), 52 deletions(-) diff --git a/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt b/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt index 788d09ee..6b92d7e9 100644 --- a/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt +++ b/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt @@ -319,7 +319,7 @@ class SchemaParser internal constructor( .build() - output.add(schemaGeneratorHelper.buildDirective(directive, graphQLDirective, directiveLocation, runtimeWiring.comparatorRegistry)) + output.add(schemaGeneratorHelper.buildAppliedDirective(directive, graphQLDirective, directiveLocation, runtimeWiring.comparatorRegistry)) } } diff --git a/src/main/kotlin/graphql/kickstart/tools/directive/SchemaDirectiveWiringEnvironmentImpl.java b/src/main/kotlin/graphql/kickstart/tools/directive/SchemaDirectiveWiringEnvironmentImpl.java index 2f754e52..291f201b 100644 --- a/src/main/kotlin/graphql/kickstart/tools/directive/SchemaDirectiveWiringEnvironmentImpl.java +++ b/src/main/kotlin/graphql/kickstart/tools/directive/SchemaDirectiveWiringEnvironmentImpl.java @@ -24,7 +24,7 @@ /* * DO NOT EDIT THIS FILE! * - * File copied from com.graphql-java.graphql-java:16.1 without any changes. + * File copied from com.graphql-java.graphql-java:17.0 without any changes. */ @Internal public class SchemaDirectiveWiringEnvironmentImpl implements SchemaDirectiveWiringEnvironment { diff --git a/src/main/kotlin/graphql/kickstart/tools/directive/SchemaGeneratorDirectiveHelper.java b/src/main/kotlin/graphql/kickstart/tools/directive/SchemaGeneratorDirectiveHelper.java index cc8c53bf..03482fe0 100644 --- a/src/main/kotlin/graphql/kickstart/tools/directive/SchemaGeneratorDirectiveHelper.java +++ b/src/main/kotlin/graphql/kickstart/tools/directive/SchemaGeneratorDirectiveHelper.java @@ -23,6 +23,7 @@ import java.util.ArrayDeque; import java.util.Deque; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -32,7 +33,7 @@ /* * DO NOT EDIT THIS FILE! * - * File copied from com.graphql-java.graphql-java:16.1 without changes except making the Parameters inner class public. + * File copied from com.graphql-java.graphql-java:17.0 without changes except making the Parameters inner class public. */ /** @@ -43,6 +44,34 @@ @Internal public class SchemaGeneratorDirectiveHelper { + /** + * This will return true if something in the RuntimeWiring requires a {@link SchemaDirectiveWiring}. This is to allow + * a shortcut to decide that that we dont need ANY SchemaDirectiveWiring post processing + * + * @param directiveContainer the element that has directives + * @param typeRegistry the type registry + * @param runtimeWiring the runtime wiring + * @param for two + * + * @return true if something in the RuntimeWiring requires a {@link SchemaDirectiveWiring} + */ + public static boolean schemaDirectiveWiringIsRequired(T directiveContainer, TypeDefinitionRegistry typeRegistry, RuntimeWiring runtimeWiring) { + + WiringFactory wiringFactory = runtimeWiring.getWiringFactory(); + + Map registeredWiring = runtimeWiring.getRegisteredDirectiveWiring(); + List otherWiring = runtimeWiring.getDirectiveWiring(); + boolean thereAreSome = !registeredWiring.isEmpty() || !otherWiring.isEmpty(); + if (thereAreSome) { + return true; + } + + Parameters params = new Parameters(typeRegistry, runtimeWiring, new HashMap<>(), null); + SchemaDirectiveWiringEnvironment env = new SchemaDirectiveWiringEnvironmentImpl<>(directiveContainer, directiveContainer.getDirectives(), null, params); + // do they dynamically provide a wiring for this element? + return wiringFactory.providesSchemaDirectiveWiring(env); + } + public static class Parameters { private final TypeDefinitionRegistry typeRegistry; private final RuntimeWiring runtimeWiring; diff --git a/src/main/kotlin/graphql/schema/idl/SchemaGeneratorHelperExt.kt b/src/main/kotlin/graphql/schema/idl/SchemaGeneratorHelperExt.kt index 8e22e46b..0d07a2d9 100644 --- a/src/main/kotlin/graphql/schema/idl/SchemaGeneratorHelperExt.kt +++ b/src/main/kotlin/graphql/schema/idl/SchemaGeneratorHelperExt.kt @@ -4,18 +4,18 @@ import graphql.introspection.Introspection import graphql.language.Directive import graphql.schema.GraphQLDirective import graphql.schema.GraphqlTypeComparatorRegistry +import graphql.schema.idl.RuntimeWiring.MOCKED_WIRING +import graphql.schema.idl.SchemaGenerator.Options.defaultOptions class SchemaGeneratorHelperExt : SchemaGeneratorHelper() { // Re-expose a package protected method as public - fun buildDirective(directive: Directive, - graphQLDirective: GraphQLDirective, - directiveLocation: Introspection.DirectiveLocation, - comparatorRegistry: GraphqlTypeComparatorRegistry): GraphQLDirective { - // Note 1: for now, it seems safe to pass buildCtx = null, since the code path where buildCtx is used, - // is never called (directive.name == graphQLDirective.name is always true, see line with - // directiveDefOpt = FpKit.findOne ...) - // Note 2: repeatable directives (new feature in graphql-java 16) likely don't work, + fun buildAppliedDirective(directive: Directive, + graphQLDirective: GraphQLDirective, + directiveLocation: Introspection.DirectiveLocation, + comparatorRegistry: GraphqlTypeComparatorRegistry): GraphQLDirective { + // Note: repeatable directives (new feature in graphql-java 16) likely don't work, // since we don't pass in the full set of discovered directives - return super.buildDirective(null, directive, setOf(graphQLDirective), directiveLocation, comparatorRegistry) + val context = BuildContext(TypeDefinitionRegistry(), MOCKED_WIRING, emptyMap(), defaultOptions()) + return super.buildAppliedDirective(context, directive, setOf(graphQLDirective), directiveLocation, comparatorRegistry) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/graphql/kickstart/tools/EndToEndSpecHelper.kt b/src/test/kotlin/graphql/kickstart/tools/EndToEndSpecHelper.kt index 8047a1ae..8335d157 100644 --- a/src/test/kotlin/graphql/kickstart/tools/EndToEndSpecHelper.kt +++ b/src/test/kotlin/graphql/kickstart/tools/EndToEndSpecHelper.kt @@ -420,11 +420,11 @@ val customScalarId = GraphQLScalarType.newScalar() else -> null } - override fun parseValue(input: Any): UUID? = parseLiteral(input) + override fun parseValue(input: Any): UUID = parseLiteral(input) - override fun parseLiteral(input: Any): UUID? = when (input) { + override fun parseLiteral(input: Any): UUID = when (input) { is StringValue -> UUID.fromString(input.value) - else -> null + else -> throw CoercingParseLiteralException() } }) .build() @@ -440,11 +440,11 @@ val customScalarUUID = GraphQLScalarType.newScalar() else -> null } - override fun parseValue(input: Any): UUID? = parseLiteral(input) + override fun parseValue(input: Any): UUID = parseLiteral(input) - override fun parseLiteral(input: Any): UUID? = when (input) { + override fun parseLiteral(input: Any): UUID = when (input) { is StringValue -> UUID.fromString(input.value) - else -> null + else -> throw CoercingParseLiteralException() } }) .build() @@ -455,12 +455,12 @@ val customScalarMap = GraphQLScalarType.newScalar() .coercing(object : Coercing, Map> { @Suppress("UNCHECKED_CAST") - override fun parseValue(input: Any?): Map = input as Map + override fun parseValue(input: Any): Map = input as Map @Suppress("UNCHECKED_CAST") - override fun serialize(dataFetcherResult: Any?): Map = dataFetcherResult as Map + override fun serialize(dataFetcherResult: Any): Map = dataFetcherResult as Map - override fun parseLiteral(input: Any?): Map = (input as ObjectValue).objectFields.associateBy { it.name }.mapValues { (it.value.value as StringValue).value } + override fun parseLiteral(input: Any): Map = (input as ObjectValue).objectFields.associateBy { it.name }.mapValues { (it.value.value as StringValue).value } }) .build() @@ -473,21 +473,18 @@ val uploadScalar: GraphQLScalarType = GraphQLScalarType.newScalar() throw CoercingSerializeException("Upload is an input-only type") } - override fun parseValue(input: Any?): Part? { + override fun parseValue(input: Any): Part { return when (input) { is Part -> { input } - null -> { - null - } else -> { throw CoercingParseValueException("Expected type ${Part::class.java.name} but was ${input.javaClass.name}") } } } - override fun parseLiteral(input: Any): Part? { + override fun parseLiteral(input: Any): Part { throw CoercingParseLiteralException( "Must use variables to specify Upload values") } diff --git a/src/test/kotlin/graphql/kickstart/tools/MethodFieldResolverTest.kt b/src/test/kotlin/graphql/kickstart/tools/MethodFieldResolverTest.kt index d6ed8549..bef07c85 100644 --- a/src/test/kotlin/graphql/kickstart/tools/MethodFieldResolverTest.kt +++ b/src/test/kotlin/graphql/kickstart/tools/MethodFieldResolverTest.kt @@ -4,6 +4,8 @@ import graphql.ExecutionInput import graphql.GraphQL import graphql.language.StringValue import graphql.schema.Coercing +import graphql.schema.CoercingParseLiteralException +import graphql.schema.CoercingSerializeException import graphql.schema.GraphQLScalarType import org.junit.Test import java.lang.reflect.InvocationHandler @@ -215,9 +217,9 @@ class MethodFieldResolverTest { val value get() = internalValue companion object { - fun of(input: Any?) = when (input) { + fun of(input: Any) = when (input) { is String -> CustomScalar(input) - else -> null + else -> throw IllegalArgumentException() } } } @@ -231,16 +233,16 @@ class MethodFieldResolverTest { .description("customScalar") .coercing(object : Coercing { - override fun parseValue(input: Any?) = CustomScalar.of(input) + override fun parseValue(input: Any) = CustomScalar.of(input) - override fun parseLiteral(input: Any?) = when (input) { + override fun parseLiteral(input: Any): CustomScalar = when (input) { is StringValue -> CustomScalar.of(input.value) - else -> null + else -> throw CoercingParseLiteralException() } - override fun serialize(dataFetcherResult: Any?) = when (dataFetcherResult) { + override fun serialize(dataFetcherResult: Any) = when (dataFetcherResult) { is CustomScalar -> dataFetcherResult.value - else -> null + else -> throw CoercingSerializeException() } }) .build() diff --git a/src/test/kotlin/graphql/kickstart/tools/SchemaClassScannerTest.kt b/src/test/kotlin/graphql/kickstart/tools/SchemaClassScannerTest.kt index 16e533ac..f5893618 100644 --- a/src/test/kotlin/graphql/kickstart/tools/SchemaClassScannerTest.kt +++ b/src/test/kotlin/graphql/kickstart/tools/SchemaClassScannerTest.kt @@ -185,9 +185,9 @@ class SchemaClassScannerTest { .name("UUID") .description("Test scalars with duplicate types") .coercing(object : Coercing { - override fun serialize(dataFetcherResult: Any?): Any? = null - override fun parseValue(input: Any?): Any? = null - override fun parseLiteral(input: Any?): Any? = null + override fun serialize(dataFetcherResult: Any): Any? = null + override fun parseValue(input: Any): Any = input + override fun parseLiteral(input: Any): Any = input }).build()) .schemaString( """ @@ -306,9 +306,9 @@ class SchemaClassScannerTest { val customMap = GraphQLScalarType.newScalar() .name("customMap") .coercing(object : Coercing, Map> { - override fun serialize(dataFetcherResult: Any?): Map = mapOf() - override fun parseValue(input: Any?): Map = mapOf() - override fun parseLiteral(input: Any?): Map = mapOf() + override fun serialize(dataFetcherResult: Any): Map = mapOf() + override fun parseValue(input: Any): Map = mapOf() + override fun parseLiteral(input: Any): Map = mapOf() }).build() val schema = SchemaParser.newParser() diff --git a/src/test/resources/Place.graphqls b/src/test/resources/Place.graphqls index dc9c7c6b..f2d66ede 100644 --- a/src/test/resources/Place.graphqls +++ b/src/test/resources/Place.graphqls @@ -18,18 +18,18 @@ interface OtherPlace { reviews: [Review!] } -type Place1 implements Entity, Place, OtherPlace { - id: ID! - name: String - other: String - reviews: [Review1!] -} - -type Place2 implements Entity, Place, OtherPlace { - id: ID! - name: String - other: String - reviews: [Review2!] +type Place1 implements Entity & Place & OtherPlace { + id: ID! + name: String + other: String + reviews: [Review1!] +} + +type Place2 implements Entity & Place & OtherPlace { + id: ID! + name: String + other: String + reviews: [Review2!] } interface Review {