Comments (6)
Makes a lot of sense ๐ Thanks for the feature request.
A version of buildPostBody
that allows writing extensions is available here (will backport in v3 in a bit).
If you are not doing file uploads, you can use the following for the time being:
class WithExtensionsHttpRequestComposer(private val serverUrl: String) : HttpRequestComposer {
override fun <D : Operation.Data> compose(apolloRequest: ApolloRequest<D>): HttpRequest {
val request = HttpRequest.Builder(HttpMethod.Post, serverUrl)
.body(
ByteStringHttpBody(
"application/json",
buildJsonByteString {
writeObject {
name("query")
value(apolloRequest.operation.document())
name("operationName")
value(apolloRequest.operation.name())
name("variables")
writeObject {
apolloRequest.operation.serializeVariables(this, apolloRequest.executionContext[CustomScalarAdapters]!!, false)
}
name("extensions")
writeObject {
name("key")
value("value")
}
}
}
)
)
.build()
return request
}
}
This is all using public API so it's not going anywhere any time soon. If you're using file uploads on the other hand, I'm afraid you'll have to copy/paste a lot of FileUploadAwareJsonWriter
until the fix gets released.
from apollo-kotlin.
Would it be possible to add a buildRequestHeaders() method to DefaultHttpRequestComposer for simplify custom composer implementaion?
Woops, sorry that fell through!
We could do something like so:
/*
* Adds the default headers to this HttpRequest.Builder:
* - Accept
* - X-APOLLO-OPERATION-ID
* - X-APOLLO-OPERATION-NAME
*/
fun HttpRequest.Builder.addDefaultHttpHeaders(): HttpRequest.Builder {}
That you could use like so:
return HttpRequest.Builder(
method = HttpMethod.Post,
url = serverUrl,
).body(
DefaultHttpRequestComposer.buildPostBody(
operation,
customScalarAdapters,
query,
) {
name("extensions")
writeObject {
name("key")
value("value")
}
}
)
.addDefaultHttpHeaders()
.build()
Heads up we are also changing the HTTP headers sent in v4. See #5533
I'm curious if you need those header specifically? Would anything break if we remove X-APOLLO-OPERATION-ID
for an example?
from apollo-kotlin.
Sorry for the delayed response. Thank you for informing us about the latest changes to Apollo!
We've confirmed that there is no issue with the changing of HTTP headers.
And so, we decided to stop sending Headers to follow the update to Apollo.
It's okay to close this issue. Thank you for your warm support and response to the request ๐
from apollo-kotlin.
Thanks for the follow up!
#5631 is now available in the SNAPSHOTs and will be in next 3.8 and 4.0-beta versions. Thanks again for surfacing this!
from apollo-kotlin.
Thanks for responding to our feature request and providing a temporary solution!
#5631 looks good to me.
We are not doing the file uploads, therefore temporary solutions looks good.
It seems that the serializeVariables function does not have a third argument.
val operation = apolloRequest.operation
val customScalarAdapters = apolloRequest.executionContext[CustomScalarAdapters] ?: CustomScalarAdapters.Empty
name("variables")
writeObject {
operation.serializeVariables(this, customScalarAdapters)
}
from apollo-kotlin.
This is another feature request.
Currently, we are copying DefaultHttpRequestComposer's requestHeaders implementations.
Would it be possible to add a buildRequestHeaders()
method to DefaultHttpRequestComposer for simplify custom composer implementaion?
class CustomHttpRequestComposer(
private val serverUrl: String,
) : HttpRequestComposer {
override fun <D : Operation.Data> compose(apolloRequest: ApolloRequest<D>): HttpRequest {
val operation = apolloRequest.operation
val requestHeaders = mutableListOf<HttpHeader>().apply {
add(HttpHeader(DefaultHttpRequestComposer.HEADER_APOLLO_OPERATION_ID, operation.id()))
add(HttpHeader(DefaultHttpRequestComposer.HEADER_APOLLO_OPERATION_NAME, operation.name()))
if (apolloRequest.operation is Subscription<*>) {
add(HttpHeader(HEADER_ACCEPT_NAME, HEADER_ACCEPT_VALUE_MULTIPART))
} else {
add(HttpHeader(HEADER_ACCEPT_NAME, HEADER_ACCEPT_VALUE_DEFER))
}
if (apolloRequest.httpHeaders != null) {
addAll(apolloRequest.httpHeaders)
}
}
return HttpRequest.Builder(
method = HttpMethod.Post,
url = serverUrl,
).addHeaders(requestHeaders)
.body(
DefaultHttpRequestComposer.buildPostBody(
operation,
customScalarAdapters,
query,
) {
name("extensions")
writeObject {
name("key")
value("value")
}
}
)
.build()
companion object {
private const val HEADER_ACCEPT_NAME = "Accept"
private const val HEADER_ACCEPT_VALUE_DEFER = "application/json"
private const val HEADER_ACCEPT_VALUE_MULTIPART = "multipart/mixed; boundary=\"graphql\"; subscriptionSpec=1.0, application/json"
}
}
from apollo-kotlin.
Related Issues (20)
- Pagination: merge `nodes` field in addition to `edges` HOT 6
- Is SSL Pinning possible with Kotlin Multi Platform HOT 4
- [IJ Plugin] Tweak navigation from GraphQL to generated code
- How to throw error apollographql based from OkHttp HOT 5
- QueueTestNetworkTransport `enqueueTestResponse` function not found in java project๏ผDoes it not support java? HOT 11
- Multi Module & Multiple Schema support HOT 7
- Run subscriptions like queries with IDE plugins HOT 3
- The tutorial API doesn't return errors when fed an unknown launch id.
- [IJ/AS plugin] Internal error: NullPointerException
- ApolloParseException is wrapping SocketException, StreamResetException HOT 1
- lateinit property context has not been initialized HOT 9
- [IJ/AS plugin] Internal error: NullPointerException HOT 2
- [IJ Plugin] Crash when navigating to GraphQL operation via margin marker
- Lazy version of `okHttpCallFactory`? HOT 2
- ApolloClient.Builder.okHttpClient() returns `null` instead of `this` HOT 1
- Use MockServer in Integration Tests (aka Mocked Automation) HOT 5
- Codegen: rework how compiled field arguments are generated
- [IJ Plugin] Specific Gradle DSL for endpoints used by the IDE plugin
- Build fails with Android 15 HOT 8
- Feature to not emit cache misses? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apollo-kotlin.