Skip to content
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

[ktor server] simplify KtorGraphQLRequestParser #1704

Merged
merged 1 commit into from
Mar 8, 2023

Conversation

dariuszkuc
Copy link
Collaborator

📝 Description

We can rely on ContentNegotiation plugin to automatically parse incoming requests for us. We don't have to read incoming requests as plain text and then attempt to manually map it.

🔗 Related Issues

We can rely on `ContentNegotiation` plugin to automatically parse incoming requests for us. We don't have to read incoming requests as plain text and then attempt to manually map it.
@dariuszkuc dariuszkuc added changes: patch Changes require a patch version module: server Issue affects the server code labels Mar 7, 2023
@dariuszkuc dariuszkuc enabled auto-merge (squash) March 7, 2023 23:10
@@ -61,9 +60,8 @@ class KtorGraphQLRequestParser(
}

private suspend fun parsePostRequest(request: ApplicationRequest): GraphQLServerRequest? = try {
val rawRequest = request.call.receiveText()
mapper.readValue(rawRequest, GraphQLServerRequest::class.java)
request.call.receive()
Copy link
Contributor

@samuelAndalon samuelAndalon Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does the ApplicationRequest instance know to which type the request payload needs to be deserialized to ? is it an inlineClass ?

request.call.receive<GraphQLServerRequest>()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type inference from the method return type -> since Jackson content negotiation is installed on the route it will deserialize it to appropriate GraphQLServerRequest (single or batch)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and yes receive is inline reified method

@dariuszkuc dariuszkuc merged commit 3db286d into ExpediaGroup:master Mar 8, 2023
@dariuszkuc dariuszkuc deleted the ktorRequestHandler branch March 8, 2023 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes: patch Changes require a patch version module: server Issue affects the server code
Development

Successfully merging this pull request may close these issues.

2 participants