Hello all. I was just working on a full stack appl...
# server
s
Hello all. I was just working on a full stack application with Kotlin and right now working on the backend. Kotlin + Spring combination looks good to me. Was just wondering whether I can use all the features of GraphQL properly with this combination because I didn't find any information regarding GraphQL on Spring's website.
a
Do you want to use graphql or spring? I dont think you can have graphql via spring
s
Any backend framework will work. Mostly looking to work with GraphQL
a
s
I actually started with this only. As I didn't find much on Spring website I was apprehensive that I would later get stuck on some problems later on. Do you think there are better server side frameworks for using Graphql with Kotlin?
j
Check out Expedia's
graphql-kotlin
project, it has a spring boot impl and can be integrated into other frameworks pretty easily.
👍 4
d
👋 for completeness -> https://expediagroup.github.io/graphql-kotlin/docs/spring-server/spring-overview *disclaimer I am one of the creators/maintainers of the lib
👍 1
s
Looks great! Will look into this. Thanks a lot
j
I'm currently using expedia's graphql implementation. It's great and really easy to use.
Also their gradle plugin for client code generation is worth looking at.
k
FYI, expedia's graphql doesn't support hashes yet...
s
Currently I don't think it would turn into a problem, but still do you know that other frameworks have the support for hashes or not?
d
FYI, expedia’s graphql doesn’t support hashes yet...
@kenkyee do you mean persisted queries (i.e. instead of specifying GraphQL request in a payload you would use HTTP GET request with some unique query identifier)? If you are using
graphql-kotlin-spring-server
you definitely can use query caching by simply providing an instance of
PreparsedDocumentProvider
in your application context (see
Query Caching
under https://www.graphql-java.com/documentation/v15/execution/). As for automatic persisted queries -> this generally requires some specific contract between client and a server (e.g. https://www.apollographql.com/docs/apollo-server/performance/apq) see related graphql-java discussion -> https://spectrum.chat/graphql-java/general/apq-automated-persisted-queries-support-question~06e249b9-b67a-49db-899b-25ad37c83fcb
k
Yes...persisted queries manifest as query hashcodes to users. Apollo has support for it and that's what we use here.
d
as per my comment -> apollo is very opinionated so they have specific contract between client and server, you could definitely implement something similar but your client and server would have to know how to calculate the same hashes and also have contract on how to negotiate new query hash registration
👍 1
r
Rolling your own support for APQ is not that hard. We’ve done so on top of graphql-java. Going with the flavor of persisted queries that Apollo has described is highly recommended as it gives clients this mechanism for free in many cases (not only Apollo Client supports APQ). We’ve ended up in a spot where we both have clients that have implemented APQ themselves and the server does so as well. Here the protocol is described: https://github.com/apollographql/apollo-link-persisted-queries
1. The client optimistically sends a query id instead of the query which is a sha256 hash of the query body. 2. If the query id is not previously known by the server, the server sends a graphql error response with a PersistedQueryNotFound message 3. The client then sends the full query body using HTTP POST, which the server then registers for future use
Neat thing is that for security you can do a lot of validation whenever a new query is registered
like for example looking at the size of the response body
And you can also limit or disable new query registration in prod