Arnab
09/30/2021, 11:20 AMobject HelloWorldQueryHandler {
fun hello(yourname: String) = "Hello $yourname"
}
class GraphQLHandler: GraphQLHandler {
private val graphql = newGraphQL(
toSchema(
SchemaGeneratorConfig(supportedPackages = listOf("no.example.capgemini")),
listOf(TopLevelObject(HelloWorldQueryHandler))
)
).build()
override fun invoke(request: GraphQLRequest): GraphQLResponse =
GraphQLResponse.from(
graphql.execute {
Builder()
.query(request.query)
.variables(request.variables)
}
)
}
fun main() {
val app = routes("/graphql" bind graphQL(GraphQLHandler()))
app.asServer(Netty()).start()
}
Now, this works when I use the GraphQL playground, but not when I use the Graphiql client. For the Graphiql client, this just returns an empty response. Am I missing something? Why is there a difference?dave
09/30/2021, 11:45 AMhandler.debug()
and sniff what the difference in request isArnab
09/30/2021, 11:50 AMhandler
object is 😮dave
09/30/2021, 11:51 AMapp.debug().asServer(Netty()).start()
Arnab
09/30/2021, 11:57 AM***** REQUEST: POST: /graphql *****
POST /graphql HTTP/1.1
Host: localhost:8000
Connection: keep-alive
accept: */*
Origin: null
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_16_0) AppleWebKit/537.36 (KHTML, like Gecko) GraphQLPlayground/1.8.10 Chrome/61.0.3163.100 Electron/2.0.11 Safari/537.36
content-type: application/json
Accept-Encoding: gzip, deflate
Accept-Language: en-GB
content-length: 84
<<stream>>
***** RESPONSE 200 to POST: /graphql *****
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{"data":{"hello":"Hello arnab"},"errors":null}
***** REQUEST: POST: /graphql *****
POST /graphql HTTP/1.1
Content-Type: application/json
User-Agent: graphiql-app
Host: localhost:8000
Connection: close
content-length: 65
<<stream>>
***** RESPONSE 400 to POST: /graphql *****
HTTP/1.1 400 Bad Request
dave
10/01/2021, 7:58 AMdebug(debugStreams=true)
instead. you'll get the content of the requestArnab
10/04/2021, 9:15 AM{"query":"{\n hello(yourname:\"Arnab\")\n}","variables":null}
gives 400, but this does not {"operationName":null,"variables":{},"query":"{\n hello(yourname: \"arnab\")\n}\n"}
I am really not sure what’s going on here. The first one is from Graphiql and the other from GraphQL playground.dave
10/04/2021, 9:19 AMdata class GraphQLRequest(val query: String = "",
val operationName: String? = null,
val variables: Map<String, Any> = emptyMap()) {
companion object {
val requestLens = Body.auto<GraphQLRequest>().toLens()
}
}
this.variables = assertNotNull(variables, () -> "variables map can't be null");
Arnab
10/04/2021, 1:49 PMdave
10/04/2021, 1:50 PMArnab
10/04/2021, 1:51 PMthis.variables = assertNotNull(variables, () -> "variables map can't be null");
dave
10/04/2021, 1:51 PMArnab
10/04/2021, 1:55 PMdave
10/04/2021, 1:55 PMArnab
10/04/2021, 2:02 PMdave
10/04/2021, 2:13 PM