Jabez Magomere
03/23/2021, 11:07 AMimport com.androidmaestro.users.data.repository.UserRepository
import com.androidmaestro.users.domain.entity.UserEntity
import com.expediagroup.graphql.types.operations.Query
import graphql.relay.*
class UsersQuery(private val repository: UserRepository) : Query{
suspend fun users(first:Int, cursor : String?) : UsersConnection = repository.getAll(first, cursor)
}
class UsersConnection(users:List<Edge<UserEntity>>, userPageInfo : DefaultPageInfo) : DefaultConnection<UserEntity>(users, userPageInfo)
However the schema generation fails with the error shown below.
Caused by: java.lang.IllegalArgumentException: Class declares 1 type parameters, but 0 were provided.
at kotlin.reflect.full.KClassifiers.createType(KClassifiers.kt:53)
at kotlin.reflect.full.KClassifiers.createType$default(KClassifiers.kt:45)
at com.expediagroup.graphql.generator.internal.types.GenerateObjectKt.generateObject(generateObject.kt:46)
at com.expediagroup.graphql.generator.internal.types.GenerateGraphQLTypeKt.getGraphQLType(generateGraphQLType.kt:74)
at com.expediagroup.graphql.generator.internal.types.GenerateGraphQLTypeKt.access$getGraphQLType(generateGraphQLType.kt:1)
at com.expediagroup.graphql.generator.internal.types.GenerateGraphQLTypeKt$objectFromReflection$1.invoke(generateGraphQLType.kt:63)
at com.expediagroup.graphql.generator.internal.types.GenerateGraphQLTypeKt$objectFromReflection$1.invoke(generateGraphQLType.kt)
at com.expediagroup.graphql.generator.internal.state.TypesCache.buildIfNotUnderConstruction$graphql_kotlin_schema_generator(TypesCache.kt:108)
at com.expediagroup.graphql.generator.internal.types.GenerateGraphQLTypeKt.objectFromReflection(generateGraphQLType.kt:62)
at com.expediagroup.graphql.generator.internal.types.GenerateGraphQLTypeKt.generateGraphQLType(generateGraphQLType.kt:40)
at com.expediagroup.graphql.generator.internal.types.GenerateGraphQLTypeKt.generateGraphQLType$default(generateGraphQLType.kt:36)
at com.expediagroup.graphql.generator.internal.types.GenerateFunctionKt.generateFunction(generateFunction.kt:54)
at com.expediagroup.graphql.generator.internal.types.GenerateFunctionKt.generateFunction$default(generateFunction.kt:33)
at com.expediagroup.graphql.generator.internal.types.GenerateQueryKt.generateQueries(generateQuery.kt:43)
at com.expediagroup.graphql.generator.SchemaGenerator.generateSchema(SchemaGenerator.kt:80)
at com.expediagroup.graphql.generator.SchemaGenerator.generateSchema$default(SchemaGenerator.kt:73)
at com.expediagroup.graphql.generator.ToSchemaKt.toSchema(toSchema.kt:41)
at com.expediagroup.graphql.generator.ToSchemaKt.toSchema$default(toSchema.kt:37)
at com.androidmaestro.graphql.Schema.<clinit>(Schema.kt:51)
... 76 common frames omitted
2021-03-23 14:01:21.087 [eventLoopGroupProxy-4-1] ERROR Application - Unhandled exception
java.lang.NoClassDefFoundError: Could not initialize class com.androidmaestro.graphql.Schema
Shane Myrick
03/23/2021, 4:33 PMJabez Magomere
03/23/2021, 5:51 PMimport com.androidmaestro.users.data.repository.UserRepository
import com.androidmaestro.users.domain.entity.UserEntity
import com.expediagroup.graphql.types.operations.Query
import graphql.relay.*
class UsersQuery(private val repository: UserRepository) : Query {
suspend fun users(first: Int, cursor : String? = null): UsersConnection = repository.getAll(first, cursor)
}
class UsersConnection(users: List<Edge<UserEntity>>, userPageInfo: DefaultPageInfo) :
DefaultConnection<UserEntity>(users, userPageInfo)
DefaultConnection snippet
/**
* A default implementation of {@link graphql.relay.Connection}
*/
@PublicApi
public class DefaultConnection<T> implements Connection<T> {
/**
}
Shane Myrick
03/23/2021, 5:56 PMJabez Magomere
03/23/2021, 6:02 PMShane Myrick
03/23/2021, 7:07 PMConnection
wrappers: https://www.graphql-java-kickstart.com/tools/relay/
You just need to make sure your schema actually defines a type and not a Connection<T>
The library just needs to know how to unwrap a Connection
, and you can do that with the schema hooks. You just need to implement the willResolveMonad
hooks similar to how you unwrap a custom async class
https://expediagroup.github.io/graphql-kotlin/docs/schema-generator/execution/async-modelsconnectionType
to return from the willGenerateGraphQLType
hook
fun willGenerateGraphQLType(type: KType): GraphQLType? {
if (type.isMyConnectionType()) {
return relay.connectionType(.....)
} else {
null
}
}
willResolveMonad
converts a KType
to a KType
that will then be used by willGenerateGraphQLType
. The end result is that you still want to have some standard GraphQL type that matches the relay spec.Filip Lastic
05/04/2022, 9:51 AM...Connection
entity for each object and then I won't have to modify hook. Because relay.connectionType(.....)
needs another GraphQLObjectType
and GraphQLFieldDefinition
fields. I am not sure if it is good idea to generate all these types in my hook