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

add support for application/graphql-response+json content type #1699

Merged
merged 3 commits into from
Mar 7, 2023

Conversation

gumimin
Copy link
Contributor

@gumimin gumimin commented Mar 6, 2023

📝 Description

Based on the accept header, spring server respond either with application/json (default) or application/graphql-response+json media type.

🔗 Related Issues

#1573

@@ -45,8 +45,9 @@ class GraphQLRoutesConfiguration(

(isEndpointRequest and isNotWebSocketRequest).invoke { serverRequest ->
val graphQLResponse = graphQLServer.execute(serverRequest)
val accept = serverRequest.headers().accept().find { it == MediaType.APPLICATION_JSON } ?: MediaType.APPLICATION_GRAPHQL_RESPONSE
Copy link
Collaborator

Choose a reason for hiding this comment

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

since application/json is current behavior I'd keep it as default for the next release as well i.e.

Suggested change
val accept = serverRequest.headers().accept().find { it == MediaType.APPLICATION_JSON } ?: MediaType.APPLICATION_GRAPHQL_RESPONSE
val acceptMediaType = serverRequest.headers().accept().find { it.includes(MediaType.APPLICATION_GRAPHQL_RESPONSE) }?.let { MediaType.APPLICATION_GRAPHQL_RESPONSE } ?: MediaType.APPLICATION_JSON

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you your review!
I've changed as the above.

endpoint: String = "graphql",
streamingResponse: Boolean = true,
jacksonConfiguration: ObjectMapper.() -> Unit = {},
acceptContentType: ContentType = ContentType("application", "graphql-response+json"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

we probably should wait for ktor 2.3.0 which includes ktorio/ktor@45b4ccd

how do we also provide a fallback to just use application/json if there is no match?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I removed support in ktor server from this PR.
I'll make another PR when ktor 2.3.0 is released. 👍

@gumimin gumimin requested a review from dariuszkuc March 7, 2023 04:11
@dariuszkuc
Copy link
Collaborator

Thanks for the PR!

@dariuszkuc dariuszkuc added changes: patch Changes require a patch version module: server Issue affects the server code labels Mar 7, 2023
@dariuszkuc dariuszkuc merged commit 207b762 into ExpediaGroup:master Mar 7, 2023
dariuszkuc pushed a commit that referenced this pull request Sep 6, 2023
…application/graphql-response+json (#1832)

### 📝 Description
Most clients will request with `*/*` unless an any MediaType is
specified.
However, the `*/*` was not taken into account in current implementation.

I change to keep `application/json` as default instead of
`application/graphql-response+json`.

### 🔗 Related Issues
#1831
#1573
#1699
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