-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce a ktor feature #37
Comments
Hello, |
I started to look at this last week. Quickly ran into the question of what would be the best way to solve this? I was thinking of just making a extension function to ktor's install(Routing) {
graphql {
query("myType") {
resolver { -> "Hello World" }
}
}
// ... Your other normal routes
} I would like to have easy setup of different things like:
So I wanted to design the API before going directly to implementation. [Edit - August 2020]: This was just a suggestion and is not what we ended with. Please look at the docs for the correct instructions for setting GraphQL up within ktor. install(WebSockets)
install(Routing) {
// Wrapping this inside a `Route.authenticate`, should work out of the box also.
graphql {
configure {
// Setting this to true would return a web app of [https://github.com/prisma-labs/graphql-playground]
// Only when a HTTP method is `GET` and HTTP Accept header has `text/html`
playground = true
}
query("myType") {
resolver { ctx: Context ->
// This User will come directly from the
val user = ctx.get<User>()
"Hello ${user.name}"
}
}
}
} We can maybe wait a bit with the web sockets part, as that is mostly for subscription queries. Other than that I would love to hear input, how would you imagine the usage would be? |
You are welcome to come with a pull request for this 😃 Then I can put my focus on something else instead |
I have not thought about the design yet but you have already helped me with your idea that I like very much, I will try to implement it and make a pull request so that we can discuss it at that time |
I have created some basic code that you can look at here: 82c6203 I tried using Kotlin Serilization instead of Gson, but ran into some problems and just went with Gson in that example. I would love it to use Kotlin Serialization or even better it would just use whatever implementation that they have used within their ContentNegotiation configuration. So we will be one step closer to multiplatform support(#6) |
Hello, guys. I try to use the Ktor plugin and found a problem but I do not know it is a bug or just I don`t understand how it works. I migrated our code to use the Ktor plugin and it works well. After that, I tried to use the playground but is it not work with basic authentication and return with HTTP 401 in any way. It is a little confusing because it works with Ktor client and Insomnia as well. Can you help to fix or understand the problem? |
@zole40 Could you provide some more information about your setup? As for the small examples that I have tested it with, it does work. If possible it would be great if you could create a small example setup of where it fails, then I can fully investigate what's going wrong. |
I used a simple configuration like this for test it:
When I call it from Insomnia, it works. But when navigate to the playground |
I got a completely different issue Are you making the request from a separate machine than where the ktor server is on? If so it seems like you should look at setting up CORS |
I making a request from the same machine. |
Would be nice to make this into a multi project and create a ktor feature which adds a
/graphql
route. And would have some configuration support to allow graphiql support out of the boxStatus:
wrap
/context
are not easy to understandGraphQLError
out of the box which are following the Spec error formatThe text was updated successfully, but these errors were encountered: