Skip to content

Update dependency com.graphql-java:graphql-java to v17 #560

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<kotlin.version>1.5.0</kotlin.version>
<kotlin-coroutines.version>1.5.0-native-mt</kotlin-coroutines.version>
<jackson.version>2.12.4</jackson.version>
<graphql-java.version>16.2</graphql-java.version>
<graphql-java.version>17.0</graphql-java.version>

<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends GraphQLDirectiveContainer> implements SchemaDirectiveWiringEnvironment<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -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.
*/

/**
Expand All @@ -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 <T> for two
*
* @return true if something in the RuntimeWiring requires a {@link SchemaDirectiveWiring}
*/
public static <T extends GraphQLDirectiveContainer> boolean schemaDirectiveWiringIsRequired(T directiveContainer, TypeDefinitionRegistry typeRegistry, RuntimeWiring runtimeWiring) {

WiringFactory wiringFactory = runtimeWiring.getWiringFactory();

Map<String, SchemaDirectiveWiring> registeredWiring = runtimeWiring.getRegisteredDirectiveWiring();
List<SchemaDirectiveWiring> otherWiring = runtimeWiring.getDirectiveWiring();
boolean thereAreSome = !registeredWiring.isEmpty() || !otherWiring.isEmpty();
if (thereAreSome) {
return true;
}

Parameters params = new Parameters(typeRegistry, runtimeWiring, new HashMap<>(), null);
SchemaDirectiveWiringEnvironment<T> 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;
Expand Down
20 changes: 10 additions & 10 deletions src/main/kotlin/graphql/schema/idl/SchemaGeneratorHelperExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't pass null here anymore.
This should keep working for now, but we might want to think of a better approach.

return super.buildAppliedDirective(context, directive, setOf(graphQLDirective), directiveLocation, comparatorRegistry)
}
}
}
25 changes: 11 additions & 14 deletions src/test/kotlin/graphql/kickstart/tools/EndToEndSpecHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,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()
Expand All @@ -472,11 +472,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()
Expand All @@ -487,12 +487,12 @@ val customScalarMap = GraphQLScalarType.newScalar()
.coercing(object : Coercing<Map<String, Any>, Map<String, Any>> {

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

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

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

Expand All @@ -505,21 +505,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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
}
Expand All @@ -231,16 +233,16 @@ class MethodFieldResolverTest {
.description("customScalar")
.coercing(object : Coercing<CustomScalar, String> {

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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ class SchemaClassScannerTest {
.name("UUID")
.description("Test scalars with duplicate types")
.coercing(object : Coercing<Any, Any> {
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(
"""
Expand Down Expand Up @@ -306,9 +306,9 @@ class SchemaClassScannerTest {
val customMap = GraphQLScalarType.newScalar()
.name("customMap")
.coercing(object : Coercing<Map<String, Any>, Map<String, Any>> {
override fun serialize(dataFetcherResult: Any?): Map<String, Any> = mapOf()
override fun parseValue(input: Any?): Map<String, Any> = mapOf()
override fun parseLiteral(input: Any?): Map<String, Any> = mapOf()
override fun serialize(dataFetcherResult: Any): Map<String, Any> = mapOf()
override fun parseValue(input: Any): Map<String, Any> = mapOf()
override fun parseLiteral(input: Any): Map<String, Any> = mapOf()
}).build()

val schema = SchemaParser.newParser()
Expand Down
24 changes: 12 additions & 12 deletions src/test/resources/Place.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down