Skip to content

Add Future support and example app #2

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

Open
wants to merge 6 commits into
base: update-to-vapor-3
Choose a base branch
from

Conversation

noahemmet
Copy link

Hi! I've updated this framework to

  • Use SwiftNIO's Futures, instead of GCD.
  • Add an example app, which mirrors the default Vapor 3 project structure.
  • Fix a couple small GraphiQL bugs.

(Note that until GraphQLSwift/GraphQL#43 is merged, I'm pointing to my custom branch of GraphQLSwift.)

Thanks very much for this framework, I think it will make setting up a Swift GraphQL server much, much easier!

@@ -9,17 +9,30 @@ let package = Package(
.library(
name: "VaporGraphQL",
targets: ["VaporGraphQL"]),
.library(
name: "StarWars",
Copy link
Author

Choose a reason for hiding this comment

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

I moved these to a separate framework so they can be referenced from both the tests and the example app.

@@ -0,0 +1,11 @@
import Vapor

/// Creates an instance of Application. This is called from main.swift in the run target.
Copy link
Author

Choose a reason for hiding this comment

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

These are just Vapor's default new project files.

@@ -74,7 +74,7 @@ extension Droid : MapFallibleRepresentable {}
* This implements the following type system shorthand:
* enum Episode { NEWHOPE, EMPIRE, JEDI }
*/
let EpisodeEnum = try! GraphQLEnumType(
Copy link
Author

Choose a reason for hiding this comment

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

I lowercased these instances to be more Swift-y.

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
query = try container.decode(String.self, forKey: .query)
// the decoder has trouble decoding a nil `[String: Map]`, so we'll use an optional throw.
Copy link
Author

Choose a reason for hiding this comment

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

This was an odd bug, the decoder was failing here. This manual try? approach fixes it but there may be a better way?

@@ -94,7 +94,7 @@ extension GraphQLService {
/// Returns an introspection of the GraphQL schema.
public func executeIntrospectionQuery(for req: Request) -> Future<Map> {
return self.execute(
GraphQLExecutionRequest(query: introspectionQuery, variables: [:], operationName: ""),
GraphQLExecutionRequest(query: introspectionQuery, variables: [:], operationName: nil),
Copy link
Author

Choose a reason for hiding this comment

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

This was another weird bug: we check for isEmpty later, and it needs to fail in order to properly render. Passing in nil fixes it.

@nonfungibletunji
Copy link

Is there a branch o can run now

@noahemmet
Copy link
Author

You can add

.package(url: "https://github.com/noahemmet/GraphQLRouteCollection.git", .branch("futures"))

to your Package.swift's dependencies if you'd like to test. Please let me know if you find any bugs or weird behavior!

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.

2 participants