https://kotlinlang.org logo
Title
r

Razvan

08/10/2021, 3:17 PM
@dave I can't run the GraphQL example any idea why... I see you changed it not long ago... I copy pasted it move it in the right package yet still got:
Exception in thread "main" java.lang.ExceptionInInitializerError
	at guide.reference.graphql.TmpKt.main(Tmp.kt:32)
	at guide.reference.graphql.TmpKt.main(Tmp.kt)
Caused by: com.expediagroup.graphql.generator.exceptions.EmptyQueryTypeException: Invalid query object type - no valid queries are available.
In fact I was trying to look for an error I got since last update... I think in the latest htt4k you changed the dependency to graphql-java 17... wihich in theirs Scalar models they removed the Long, BigInt ... but graphql-kotlin-schema-generator 4.1.1 was not updated (seems like too busy with 5.0,0 alphas, they don't bother to support 4,1,1) so in their generateScalar.kt they try to use GraphQLLong, Short, BigDecimal, BigInteger and Char which are no longer supported by graphql-java...
d

dave

08/10/2021, 3:26 PM
yeah - there seems to be a change that they've made to the graphql library - I haven't had chance to look at it. but I know it's breaking the toolbox build 😢
If you revert to an old version, does that example run ok?
r

Razvan

08/10/2021, 3:27 PM
I thing going back to graphql-java 16 should fix it
until schema 5.0.0 as in their master branch is all good the old scalar are no longer there
d

dave

08/10/2021, 3:28 PM
If I get a chance later I'll revert it back down..
r

Razvan

08/10/2021, 3:50 PM
FWIW going back to 4.10.1.0 of http4k (which uses graphql-java 16.2) fixes my problems... yet not your exemple I think it really requires a query in the
toSchema(queries=)
list and empty is not valid Error explicetly say that:
Caused by: com.expediagroup.graphql.generator.exceptions.EmptyQueryTypeException: Invalid query object type - no valid queries are available.
d

dave

08/10/2021, 3:51 PM
ah - ok. There is a model lacking in there somewhere... 🙂
r

Razvan

08/10/2021, 4:02 PM
and a query somthing dumb as:
object MyGraphQLHandler : GraphQLHandler {
    private val graphQL = newGraphQL(
        toSchema(
            SchemaGeneratorConfig(supportedPackages = listOf("guide.reference.graphql")),
            listOf(TopLevelObject(UserQuery())),
            listOf()
        )).build()

    override fun invoke(request: GraphQLRequest) = GraphQLResponse.from(graphQL.execute(request.query))
}

data class User(val name: String, val email: String)

class UserQuery {
    fun create(name: String): User = User(name, "$name@$<http://name.com|name.com>")
}

fun main() {
    val app: HttpHandler = routes(
        "/graphql" bind graphQL(MyGraphQLHandler)
    )

    // serve GQL queries/mutations at /graphql
    val server = app.asServer(SunHttp(8000)).start()

    // for clients, just convert any app into a GQL handler
    val gql: GraphQLHandler = JavaHttpClient().asGraphQLHandler(Uri.of("<http://localhost:8000/graphql>"))
    val response: GraphQLResponse = gql(GraphQLRequest(" { create(name: \"Tom\") { email } }"))
    println(response)
}
}
works...
d

dave

08/10/2021, 4:04 PM
If you fancy PRing it to make it work then that would be amazeballs 🙂
r

Razvan

08/10/2021, 4:05 PM
ok
Yet you still have to revert the 4.11.0.0 upgrade of graphql-java as the example fails in this version with the error I was getting about the scalar type:
Exception in thread "main" java.lang.NoSuchFieldError: GraphQLLong
	at com.expediagroup.graphql.generator.internal.types.GenerateScalarKt.<clinit>(generateScalar.kt:41)
d

dave

08/10/2021, 4:09 PM
yep - happy for your to downgrade that at the same time TBH.
r

Razvan

08/10/2021, 4:10 PM
ok doing this evening. thanks
d

dave

08/10/2021, 4:10 PM
amazing! TYVM! 🙂