aPureBase / KGraphQL

Pure Kotlin GraphQL implementation
https://kgraphql.io
MIT License
301 stars 58 forks source link

"Generic types are not supported by GraphQL" #154

Open Digital-Nomad opened 3 years ago

Digital-Nomad commented 3 years ago

I am running into this error in my project:

Exception in thread "main" com.apurebase.kgraphql.schema.SchemaException: Generic types are not supported by GraphQL, found kotlin.collections.Map<org.jetbrains.exposed.sql.Expression<*>, kotlin.Int>
    at com.apurebase.kgraphql.schema.structure.SchemaCompilation.handlePossiblyWrappedType(SchemaCompilation.kt:168)
    at com.apurebase.kgraphql.schema.structure.SchemaCompilation.handleKotlinProperty(SchemaCompilation.kt:372)

My project is located here. If you take a look at my ExposedFeed.kt, you can see I setup the Exposed DAO classes as they are shown in the Exposed examples but in your example code you use data class and you don't need to define the type it seems. Is this why I am running into this error?

jeggy commented 3 years ago

I haven't tested KGraphQL integration with Exposed before. But I can see they don't work so well together 😮

The issue is that your ExposedFeed class is extending the IntEntity which is extending Entity<Int> and this class provided by exposed includes some public fields that KGraphQL is trying to make available on your GraphQL Type.

KGraphQL has an option to ignore fields on a specific type. To get this to work you would need to specify this on all of your exposed types

// 1kotlin classes need to be registered with "type" method
// to be included in created schema type system
// class Character is automatically included,
// as it is return type of both created queries
type<ExposedFeed> {
    ExposedFeed::id.ignore()
    ExposedFeed::klass.ignore()
    ExposedFeed::db.ignore()
    ExposedFeed::writeValues.ignore()
    ExposedFeed::_readValues.ignore()
    ExposedFeed::readValues.ignore()
}
type<ExposedEntry> {
    ExposedEntry::id.ignore()
    ExposedEntry::klass.ignore()
    ExposedEntry::db.ignore()
    ExposedEntry::writeValues.ignore()
    ExposedEntry::_readValues.ignore()
    ExposedEntry::readValues.ignore()
}

I have created a new issue to provide better error reporting on these types of errors https://github.com/aPureBase/KGraphQL/issues/155

Digital-Nomad commented 3 years ago

Ignoring those functions, I now get the following error:

Couldn't retrieve 'author' from class org.jetbrains.exposed.sql.IterableExKt$mapLazy$1@6a992897}", With this query

query {
  RSSFeeds
  {
    author
  }