GraphQL support would be awesome, especially in a nice fluent javalin-style implementation with integration into javalin.
Links:
https://github.com/facebook/graphql
https://graphql.org/
A Kotlin implementation:
https://github.com/pgutkowski/KGraphQL
A Java implementation:
https://github.com/graphql-java/graphql-java
Hi @steph4nc. Could you elaborate a bit on what you want this feature to include? I haven't set up a graphql project before, but I was under the impression that you would primarily have one endpoint. Connecting one endpoint to graphql should be easy enough in Javalin, what can be done to make it easier?
Hi @tipsy! Look at my poc for this idea: https://github.com/7agustibm/javalin-graphql.
Maybe, it would be interesting to create a plugin.
Cool, will have a look later!
@7agustibm it doesn't look like much code is needed in the first place, what do you think the plugin should be responsible for?
@7agustibm ping.
Sorry @tipsy! Yes, I can do it. Should it be completely separate or do you want to add it as a feature?
If I understand the code correctly it looks like it can be added similar to JavalinJson and JavalinRenderer, so JavalinGraphQl. Does that sound right?
Ok. I look at the JavalinJson packet and I do a PR when I have it.
Hi @tipsy! I have a PoC. You can see in this file https://github.com/7agustibm/javalin/blob/master/src/test/kotlin/io/javalin/examples/HelloWorldGraphQL.kt how to work. I have a little problem with integration expedia-graphql and javalin.
@7agustibm Looks simple enough! What's the problem?
When start demo with graphql-kotlin, return this errors:
[main] INFO io.javalin.Javalin -
__ __ _
/ /____ _ _ __ ____ _ / /(_)____
__ / // __ `/| | / // __ `// // // __ \
/ /_/ // /_/ / | |/ // /_/ // // // / / /
\____/ \__,_/ |___/ \__,_//_//_//_/ /_/
https://javalin.io/documentation
[main] INFO org.eclipse.jetty.util.log - Logging initialized @442ms to org.eclipse.jetty.util.log.Slf4jLog
[main] INFO io.javalin.Javalin - Starting Javalin ...
[main] INFO io.javalin.Javalin - Listening on http://localhost:7070/
[main] INFO io.javalin.Javalin - Javalin started in 312ms \o/
[main] INFO org.reflections.Reflections - Reflections took 219 ms to scan 1 urls, producing 257 keys and 1263 values
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.Sets$SetView.iterator()Lcom/google/common/collect/UnmodifiableIterator;
at org.reflections.Reflections.expandSuperTypes(Reflections.java:380)
at org.reflections.Reflections.<init>(Reflections.java:126)
at org.reflections.Reflections.<init>(Reflections.java:168)
at com.expedia.graphql.generator.SubTypeMapper.<init>(SubTypeMapper.kt:8)
at com.expedia.graphql.generator.SchemaGenerator.<init>(SchemaGenerator.kt:31)
at com.expedia.graphql.ToSchemaKt.toSchema(toSchema.kt:22)
at io.javalin.http.graphql.JavalinGraphql.build(JavalinGraphql.kt:37)
at io.javalin.examples.HelloWorldGraphQLKt.main(HelloWorldGraphQL.kt:22)
I'm working with this problem.
Maybe, the best solution and simple, for me, is:
app.graphql("/graphql")
For post request, it's same code for now with build and return response, but in get request return GraphQLi and it's more simple.
Looks like there might be a conflict in your dependencies?
Yes, it's. I updated the guava version of last version.
I guess this is the downside of having the hacky optional dependencies? 馃
Maybe, it's... Maybe it should be loaded as a plugin completely separate of Kotlin.
For exemple:
val graphQL = KotlinGraphQL()
app.loadingPlugin(graphQL)
That wouldn't change the problem of dependency collisions, for that we would need to publish separate packages per plugin, but that's unlikely to happen. I'm not sure how specifying versions for optional transitive dependencies works, it sounds like a bit of a mess.
Ok. Update the last version of kotlin-graphql with subscriptions and I create a PR.
@tipsy I have the first version with Query, Mutation and Subscription with query and variables. Just missing context data. Do you want to create PR with WIP in the description for review?
Sure, that would be great!
After two years, this can finally be closed 馃榿
We have GraphQL on Javalin?? :O
Yes, there is a new plugin and module, check the docs :)