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

Feature Request: Async RequestBodyCreator for Async Auth Payload Retrieval #3416

Open
lawmicha opened this issue Jul 22, 2024 · 3 comments
Open
Assignees
Labels
feature New addition or enhancement to existing solutions networking-stack

Comments

@lawmicha
Copy link

lawmicha commented Jul 22, 2024

Use case

Integrating asynchronous token providers and SigV4 signers with Apollo iOS is challenging due to the synchronous nature of the current requestBody method in the RequestBodyCreator protocol. This limitation forces the implementation to use a semaphore when needing to wait for the async operations to finish.

Describe the solution you'd like

An asynchronous version of requestBody

func asyncRequestBody<Operation: GraphQLOperation>(
    for operation: Operation,
    sendQueryDocument: Bool,
    autoPersistQuery: Bool
  ) async throws -> JSONEncodableDictionary

Is there an existing solution or alternative approach for handling this that I might have missed?

@lawmicha lawmicha added the feature New addition or enhancement to existing solutions label Jul 22, 2024
@calvincestari
Copy link
Member

Hi @lawmicha, we're working on a number of changes for Swift 6 and Sendable support at the moment which is requiring us to rework the network API for first-class support of Swift Concurrency. So this probably won't happen in the 1.x branch but we may be able to work this into the networking changes.

@AnthonyMDev - here's something to take note of for the work you're doing now.

@lawmicha
Copy link
Author

lawmicha commented Jul 23, 2024

Hi @calvincestari, thanks for the quick response and for sharing the plans to support Swift Concurrency.

I’d like to create a package that depends on Apollo using the upToNextMajor version from 1.x. This will provide developers with the flexibility to stay on their current version of Apollo library until they’re ready to upgrade to the latest 1.x or 2.x release. Meanwhile, they can start using the custom RequestBodyCreator I’m writing.

However, to implement a custom RequestBodyCreator, I need the requestBody method to be asynchronous. Is there a possibility to introduce this async support in 1.x? I can drive the contribution to minimize the effort on your team. My initial proposal would look like this.

  • Introduce a new RequestBodyCreatorAsync protocol with an async version of requestBody. This allows developers to opt-in and ensures backward compatibility, allowing it to be shipped as a minor version update in 1.x rather than a major breaking change. Currently, I've defined it using an escaping closure, but alternatively, we can use async throws if that fits better with the Swift Concurreny plans.
  • Modify WebSocketTransport.sendHelper to pivot on the async and non-async versions when calling requestBody.

I can take this forward if I can get your team's input and decisions for achieving this in 1.x.

Thank you for your consideration!

@AnthonyMDev AnthonyMDev self-assigned this Aug 9, 2024
@AnthonyMDev AnthonyMDev added this to the Next Major Release milestone Aug 9, 2024
@AnthonyMDev
Copy link
Contributor

Thanks for all the detailed information you've given us on your approach here. I'm going to be getting this implemented for the 2.0 version that we are currently working on.

We feel that back porting this to 1.x is not a very clean solution and we prefer to have this just wait for the coming 2.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New addition or enhancement to existing solutions networking-stack
Projects
None yet
Development

No branches or pull requests

3 participants