GraphQLSwift / Graphiti

The Swift GraphQL Schema framework for macOS and Linux
MIT License
531 stars 67 forks source link

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

Closed cshadek closed 1 year ago

cshadek commented 3 years ago

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

cshadek commented 3 years ago

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

alobaili commented 2 years ago

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!

paulofaria commented 2 years ago

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 commented 2 years ago

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.

cshadek commented 2 years ago

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

NeedleInAJayStack commented 2 years ago

@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 commented 2 years ago

@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()
cshadek commented 2 years ago

@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 commented 2 years ago

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

NeedleInAJayStack commented 2 years ago

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.

cshadek commented 2 years ago

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 commented 2 years ago

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.

NeedleInAJayStack commented 2 years ago

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

d-exclaimation commented 2 years ago

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.

NeedleInAJayStack commented 1 year ago

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