Skip to content
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
9 changes: 7 additions & 2 deletions src/main/kotlin/graphql/kickstart/tools/GenericType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
TypeUtils.isAssignable(genericInterface, targetInterface)
} ?: raw.interfaces.find { iface ->
TypeUtils.isAssignable(iface, targetInterface)
} ?: getGenericInterface(raw.genericSuperclass, targetInterface) ?: return null

Check warning on line 59 in src/main/kotlin/graphql/kickstart/tools/GenericType.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this useless elvis operation ?:, it always succeeds.

See more on https://sonarcloud.io/project/issues?id=graphql-java-kickstart_graphql-java-tools&issues=AaD-i39qyBL9wOjKFG4o&open=AaD-i39qyBL9wOjKFG4o&pullRequest=819

return getGenericInterface(possibleSubInterface, targetInterface)
}
Expand Down Expand Up @@ -151,8 +151,13 @@
}
}
is TypeVariable<*> -> {
if (declaringType is ParameterizedType) {
TypeUtils.getRawType(type, declaringType)
val genericDeclaration = type.genericDeclaration
if (declaringType is ParameterizedType && genericDeclaration is Class<*>) {
// keep the full type argument (e.g. List<Foo>) rather than its raw class so nested generics aren't lost
TypeUtils.getTypeArguments(declaringType, genericDeclaration)?.get(type)
?.takeIf { it != type }
?.let { replaceTypeVariable(it) }
?: type
} else {
type
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
resolverInfosByDataClass[item.clazz] ?: DataClassResolverInfo(item.clazz)
}
})
?: throw SchemaClassScannerError("The GraphQL schema type '${item.type.name}' maps to a field of type java.lang.Object however there is no matching entry for this type in the type dictionary. You may need to add this type to the dictionary before building the schema.")

Check warning on line 293 in src/main/kotlin/graphql/kickstart/tools/SchemaClassScanner.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this useless elvis operation ?:, it always succeeds.

See more on https://sonarcloud.io/project/issues?id=graphql-java-kickstart_graphql-java-tools&issues=AaD-i36-yBL9wOjKFG4n&open=AaD-i36-yBL9wOjKFG4n&pullRequest=819

scanResolverInfoForPotentialMatches(item.type, resolverInfo)
}
Expand Down Expand Up @@ -368,7 +368,7 @@
handleFoundType(typeClassMatcher.match(TypeClassMatcher.PotentialMatch.parameterType(
inputValueDefinition.type,
inputValueJavaType,
GenericType(javaType, options).relativeToType(inputValueJavaType),
GenericType(javaType, options).relativeToType(javaType),
InputObjectReference(inputValueDefinition)
)))
} else {
Expand Down
103 changes: 103 additions & 0 deletions src/test/kotlin/graphql/kickstart/tools/GenericInputTypesTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package graphql.kickstart.tools

import graphql.GraphQL
import org.junit.Test

class GenericInputTypesTest {

@Test
fun `generic input types are parsed`() {
val schema = SchemaParser.newParser()
.schemaString(
"""
type Query {
audit(input: LanguageAudit!): String!
audits(input: LanguageAudits!): String!
}

input LanguageAudit {
content: LanguageInput!
operator: String!
}

input LanguageAudits {
content: [LanguageInput!]!
operator: String!
}

input LanguageInput {
id: ID!
}
""")
.resolvers(QueryResolver())
.build()
.makeExecutableSchema()
val gql = GraphQL.newGraphQL(schema).build()

val data = assertNoGraphQlErrors(gql) {
"""
query {
audit(input: { content: { id: "1" }, operator: "op" })
audits(input: { content: [{ id: "2" }, { id: "3" }], operator: "op" })
}
"""
}

assertEquals(data["audit"], "op:1")
assertEquals(data["audits"], "op:2,3")
}

@Test
fun `generic input types inherited from a parameterized superclass are parsed`() {
val schema = SchemaParser.newParser()
.schemaString(
"""
type Query {
audit(input: LanguageAudit!): String!
}

input LanguageAudit {
content: LanguageInput!
operator: String!
}

input LanguageInput {
id: ID!
}
""")
.resolvers(InheritedQueryResolver())
.build()
.makeExecutableSchema()
val gql = GraphQL.newGraphQL(schema).build()

val data = assertNoGraphQlErrors(gql) {
"""
query {
audit(input: { content: { id: "1" }, operator: "op" })
}
"""
}

assertEquals(data["audit"], "op:1")
}

class QueryResolver : GraphQLQueryResolver {
fun audit(input: AuditWrapper<LanguageInput>): String = "${input.operator}:${input.content?.id}"
fun audits(input: AuditWrapper<List<LanguageInput>>): String = "${input.operator}:${input.content?.joinToString(",") { it.id.orEmpty() }}"
}

class InheritedQueryResolver : GraphQLQueryResolver {
fun audit(input: LanguageAuditWrapper): String = "${input.operator}:${input.content?.id}"
}

open class AuditWrapper<T> {
var content: T? = null
var operator: String? = null
}

class LanguageAuditWrapper : AuditWrapper<LanguageInput>()

class LanguageInput {
var id: String? = null
}
}
Loading