Skip to content

Conversation

BoD
Copy link
Contributor

@BoD BoD commented Dec 17, 2024

Implements the latest (as of 2025-09-24) @defer incremental response format as seen in examples and spec edits.

A protocol can now be passed to the HttpNetworkTransport to choose which to use (legacy 20220824 is still the default).

@svc-apollo-docs
Copy link
Collaborator

svc-apollo-docs commented Dec 17, 2024

✅ Docs Preview Ready

Configuration
{
  "repoOverrides": {
    "apollographql/apollo-kotlin@main": {
      "remote": {
        "owner": "apollographql",
        "repo": "apollo-kotlin",
        "branch": "defer-incremental-response-format-june-2023"
      }
    }
  }
}
Name Link

Commit

e2da859

Preview

https://www.apollographql.com/docs/deploy-preview/1919dfd3b4a18c13cba2

Build ID

1919dfd3b4a18c13cba2

File Changes

0 new, 1 changed, 0 removed
* (developer-tools)/kotlin/(latest)/caching/declarative-ids.mdx

Pages

1


1 pages published. Build will be available for 30 days.

@BoD BoD force-pushed the defer-incremental-response-format-june-2023 branch from e2da859 to bb504f6 Compare July 17, 2025 09:39
@apollo-librarian
Copy link

apollo-librarian bot commented Jul 17, 2025

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

0 new, 1 changed, 0 removed
* (developer-tools)/kotlin/v5/index.mdx

Build ID: 65212b0a9c9b1f3e8aaf6e6a
Build Logs: View logs

URL: https://www.apollographql.com/docs/deploy-preview/65212b0a9c9b1f3e8aaf6e6a

@BoD BoD force-pushed the defer-incremental-response-format-june-2023 branch 2 times, most recently from e1ee642 to 4fa99ad Compare July 18, 2025 17:01
@martinbonnin
Copy link
Contributor

Apollo Client 4 introduces different handlers for different incremental formats. We could do the same while the format iterates.

@BoD BoD force-pushed the defer-incremental-response-format-june-2023 branch 2 times, most recently from 95e0b8c to fc4f174 Compare September 24, 2025 16:15
@BoD BoD force-pushed the defer-incremental-response-format-june-2023 branch from fc4f174 to 8dfc4b3 Compare September 24, 2025 16:23
@BoD BoD marked this pull request as ready for review September 25, 2025 07:44
@BoD BoD requested a review from martinbonnin as a code owner September 25, 2025 07:44
this.engine = httpEngine
}

fun incrementalDeliveryProtocol(incrementalDeliveryProtocol: IncrementalDeliveryProtocol) = apply {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing KDoc here

Also, looks like apollo-client went with incrementalHandler. Might be worth reusing some of the terminology? But we also have "protocol" for other things like WebSockets so my logaf is low.

Comment on lines 232 to 243
public final class com/apollographql/apollo/internal/incremental/Defer20220824IncrementalResultsMerger : com/apollographql/apollo/internal/incremental/IncrementalResultsMerger {
public fun <init> ()V
public fun getHasNext ()Z
public fun getIncrementalResultIdentifiers ()Ljava/util/Set;
public fun getMerged ()Ljava/util/Map;
public fun isEmptyResponse ()Z
public fun merge (Ljava/util/Map;)Ljava/util/Map;
public fun merge (Lokio/BufferedSource;)Ljava/util/Map;
public fun reset ()V
}

public final class com/apollographql/apollo/internal/incremental/GraphQL17Alpha9IncrementalResultsMerger : com/apollographql/apollo/internal/incremental/IncrementalResultsMerger {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit weird that one is Defer20220824 and the other GraphQL17Alpha9. I haven't followed all the latest discussions lately but could we somwhat uniformized that? Are there specs versions (or tags) somewhere that describe what each one is doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn’t look like there are any tags on the spec itself, so using graphql-js versions is cool. So maybe we should rename Defer20220824 to whatever version of graphql-js it corresponds to, for consistency. For now I kept the same naming as Apollo Client, but maybe it’s not too late to change the name there too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. Let's keep a practical approach here and do whatever is easiest. This is all experimental so the whole point is to move fast and iterate 👍

* Both `@defer` and `@stream` are supported with this format.
*/
object GraphQL17Alpha9 : IncrementalDeliveryProtocolImpl {
// TODO To be agreed upon with the router and other clients
Copy link
Contributor Author

Choose a reason for hiding this comment

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

payloadResponse != null -> payloadResponse
else -> null
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to test from the response whether it supports the incremental delivey protocol? Is there something in response.headers["content-type"] that signals what protocol was used by the server?

Comment on lines 46 to 54
if (get("accept") == null) {
add(
HttpHeader("accept",
if (apolloRequest.operation is Subscription<*>) {
"multipart/mixed;subscriptionSpec=1.0, application/graphql-response+json, application/json"
} else {
"multipart/mixed;deferSpec=20220824, application/graphql-response+json, 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.

I’ve kept this here because if somebody is using DefaultHttpRequestComposer but not HttpNetworkTransport it’s a behavior change (no accept header) - no strong opinion though.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about application/graphql-response+json, application/json as a fallback? This is the most standard accept header. This way DefaultHttpRequestComposer is isolated from the incremental delivery concerns. That's a behavior change but probably very small blast radius?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Works for me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants