Graphiti icon indicating copy to clipboard operation
Graphiti copied to clipboard

Is there a plan in place for adding support for async await?

Open cshadek opened this issue 4 years ago • 14 comments

Async-await will be added in Swift 5.5.
https://github.com/apple/swift-evolution/blob/main/proposals/0296-async-await.md

cshadek avatar Mar 31 '21 19:03 cshadek

Given that Swift 5.5 is now released, will Graphiti support async-await?

cshadek avatar Sep 24 '21 15:09 cshadek

Hello @cshadek, @paulofaria and @adam-fowler For organization, I think this issue should be reopened and linked to https://github.com/GraphQLSwift/Graphiti/pull/71

It appears that support for async/await is a big undertaking. I really hope to see it implemented some day.

I've just started learning about this package from https://www.raywenderlich.com/21148796-graphql-tutorial-for-server-side-swift-with-vapor-getting-started

It's a great package, thank you all for your hard work!

alobaili avatar May 23 '22 21:05 alobaili

Hi, thank you for your kindness. I will try to finish this by the end of the month. The async part itself is mostly done. It's just that I took the chance to improve the API so we can release a new major version and life got in the way.

paulofaria avatar May 23 '22 23:05 paulofaria

I was also waiting on https://github.com/apple/swift-evolution/blob/main/proposals/0348-buildpartialblock.md to improve the API greatly. Instead of using classes and initializers for the Schema definition, we'll be able to use functions and structs, which will make the API look much closer to the GraphQL SDL.

paulofaria avatar May 24 '22 00:05 paulofaria

@paulofaria have you given any thought as to how subscriptions and directives fit into the new API design?

cshadek avatar May 24 '22 13:05 cshadek

@cshadek I have done a little thinking about subscriptions and async/await. The new AsyncSequence should be able to replace reactive drivers like GraphQLRxSwift.

NeedleInAJayStack avatar May 24 '22 15:05 NeedleInAJayStack

@alobaili In the meantime, you can convert any EventLoopFuture API to an async one by using EventLoopFuture.get. For example:

let result = await graphitiAPI.execute(
    request: request,
    ...
).get()

NeedleInAJayStack avatar May 24 '22 15:05 NeedleInAJayStack

@cshadek I have done a little thinking about subscriptions and async/await. The new AsyncSequence should be able to replace reactive drivers like GraphQLRxSwift.

This sounds amazing

cshadek avatar May 24 '22 15:05 cshadek

I just came across this, but it looks like this repo is already doing a lot of what we're talking about.

https://github.com/d-exclaimation/pioneer

cshadek avatar Jun 06 '22 18:06 cshadek

Woah, I hadn't seen that repo before! That's pretty awesome stuff they're doing! Yeah, it seems like we could easily bring some of the extensions they've made into this repo.

NeedleInAJayStack avatar Jun 06 '22 19:06 NeedleInAJayStack

Yeah I just found it earlier today. I really wonder if there shouldn't be some strategic partnership between Pioneer and GraphQLSwift. It's almost like they want to build Apollo Server for Swift - that would be incredible!

cshadek avatar Jun 06 '22 19:06 cshadek

It does seem like it's only one guy - which is not unheard of it, but I'd worry about it getting maintained longterm. But some of the stuff with abstracting away the web socket support and graphiQL is really nice.

cshadek avatar Jun 06 '22 19:06 cshadek

I have an PR in to GraphQL that adds async/await support, and a followup one ready for Graphiti once that one goes through.

NeedleInAJayStack avatar Jul 14 '22 15:07 NeedleInAJayStack

Woah, I hadn't seen that repo before! That's pretty awesome stuff they're doing! Yeah, it seems like we could easily bring some of the extensions they've made into this repo.

I think I can help move the async-await extensions I made from Pioneer here. The only problem with those extensions I made is that at the moment, they completely ignore the Sendable conformance which is not enforced now with Swift 5 but will be a problem later on with Swift 6 which is set to be safe-by-default and the only solution I see is @_unsafeSendable attribute but I haven't played with it yet.

d-exclaimation avatar Jul 15 '22 08:07 d-exclaimation

I'm marking this as resolved, since async/await support was added by https://github.com/GraphQLSwift/Graphiti/pull/78

NeedleInAJayStack avatar Jan 30 '23 06:01 NeedleInAJayStack