gql icon indicating copy to clipboard operation
gql copied to clipboard

[Feature] Support Subscriptions HTTP Multipart Protocol

Open andrewmcgivery opened this issue 2 years ago • 6 comments

Apollo recently introduced HTTP callback protocol for GraphQL subscriptions which utilizes the HTTP Multipart protocol instead of websockets.

Apollo Client supports it out of the box and provides adapters for Relay and urql.

Would be awesome if this library supported it!

Some reference code from Apollo Client:

  • Relay Adapter: https://github.com/apollographql/apollo-client/blob/26fe4a57323f76ba73b6a2254c447aa967daf0f4/src/utilities/subscriptions/relay/index.ts#L17
  • urql Adapter: https://github.com/apollographql/apollo-client/blob/26fe4a57323f76ba73b6a2254c447aa967daf0f4/src/utilities/subscriptions/urql/index.ts#L14
  • Code for parsing HTTP Multipart: https://github.com/apollographql/apollo-client/blob/26fe4a57323f76ba73b6a2254c447aa967daf0f4/src/link/http/parseAndCheckHttpResponse.ts#L16
  • Adding multi-part headers: https://github.com/apollographql/apollo-client/blob/26fe4a57323f76ba73b6a2254c447aa967daf0f4/src/link/http/createHttpLink.ts#L147

andrewmcgivery avatar Feb 05 '24 18:02 andrewmcgivery

I think you're mixing two different things. The HTTP callback protocol that you first linked is different than the Multipart HTTP protocol (which is on the next page of the docs).

In the callback protocol, you have to create a server and send an url to the backend so that it could send answers to your own server. In the Multipart protocol, you do an HTTP request which is long lived and will not close the connection but instead continue to send data as new events happen. There is no need for a server there.

I suppose you're interested in the Multipart protocol and not the callback protocol.

In that case, do you know a public backend which supports this protocol already that we could use to test this functionality?

leszekhanusz avatar Feb 05 '24 22:02 leszekhanusz

Yep, you're correct about the differences... also for context, I'm a Solutions Architect at Apollo. 😄

I linked both for context but yes you're correct that what I'm interested in is the client portion, the Multipart protocol.

I don't know of a public backend currently... but I can help with testing by providing a private test repo (and adding you to it) and temporarily issuing an Apollo Key to a test graph.

andrewmcgivery avatar Feb 05 '24 23:02 andrewmcgivery

@leszekhanusz @andrewmcgivery I'd be happy to help with this :)

If you need a backend for testing this I can make a an example with Strawberry (I have a PR open to add multipart support: https://github.com/strawberry-graphql/strawberry/pull/3076)

patrick91 avatar Feb 06 '24 09:02 patrick91

Yep, you're correct about the differences... also for context, I'm a Solutions Architect at Apollo. 😄

Oops :laughing:

I don't know of a public backend currently... but I can help with testing by providing a private test repo (and adding you to it) and temporarily issuing an Apollo Key to a test graph.

That would be nice, but I would like to take this opportunity to ask if you could maybe propose in your organization to make a very simple public server to allow any user to test clients for GraphQL subscriptions. I think that would be a very nice gift to the GraphQL community.

With gql, we are using https://countries.trevorblades.com for most of our examples, but they dropped the websockets endpoint, so a public GraphQL backend which supports both the websocket and multipart protocol would be really nice. The actual schema could be something really simple like a subscription for a number counting to 10 with a 100ms interval for example. The bandwidth should be minimal as this serves no purpose except for a few tests. If that's not possible, no worries I'll use the private test repo.

leszekhanusz avatar Feb 06 '24 20:02 leszekhanusz

If you need a backend for testing this I can make a an example with Strawberry (I have a PR open to add multipart support: strawberry-graphql/strawberry#3076)

That would be great!

Note for both of you: Is there a list somewhere of clients/servers supporting the multipart protocol in all languages? Something like the GraphQL file upload spec

leszekhanusz avatar Feb 06 '24 20:02 leszekhanusz

Yep, you're correct about the differences... also for context, I'm a Solutions Architect at Apollo. 😄

Oops 😆

I don't know of a public backend currently... but I can help with testing by providing a private test repo (and adding you to it) and temporarily issuing an Apollo Key to a test graph.

That would be nice, but I would like to take this opportunity to ask if you could maybe propose in your organization to make a very simple public server to allow any user to test clients for GraphQL subscriptions. I think that would be a very nice gift to the GraphQL community.

With gql, we are using https://countries.trevorblades.com for most of our examples, but they dropped the websockets endpoint, so a public GraphQL backend which supports both the websocket and multipart protocol would be really nice. The actual schema could be something really simple like a subscription for a number counting to 10 with a 100ms interval for example. The bandwidth should be minimal as this serves no purpose except for a few tests. If that's not possible, no worries I'll use the private test repo.

I'll chat internally to see what we can do. :)

andrewmcgivery avatar Feb 06 '24 22:02 andrewmcgivery