https://kotlinlang.org logo
#graphql-kotlin
Title
# graphql-kotlin
d

Dusan Hornik

10/21/2021, 5:53 AM
Hello, I am trying to implement some basic pagination and it seems like I should be using generics, but that doesn’t generate graphql schema:
Copy code
com.expediagroup.graphql.exceptions.TypeNotSupportedException: Cannot convert T since it is not a valid GraphQL type or outside the supported packages
Code:
Copy code
class MyQuery: Query {}
    suspend fun students(pageNumber:Int): Page<Student> {
      return getStudents(pageNumber)
    } 
}
data class Page<T>(val items: List<T>, pageNumber: Int)
data class Student(val name: String)
Is there a recommended way to design this?
d

Dariusz Kuc

10/21/2021, 9:55 PM
Hello 👋 TLDR generics are not supported by GraphQL spec so we don't support it either (https://github.com/ExpediaGroup/graphql-kotlin/issues/292)
While it is not ideal, the workaround is to create specific
Page
flavors (i.e.
StudentPage
instead of generic
Page<T>
)
d

Dusan Hornik

10/22/2021, 12:17 AM
Yeah, that’s what I thought so. Thank you Dariusz.
38 Views