|
2 | 2 |
|
3 | 3 | # GraphQL Generator for Swift |
4 | 4 |
|
5 | | -A Swift package plugin that generates server-side GraphQL API code from GraphQL schema files, inspired by [GraphQL Tools' makeExecutableSchema](https://the-guild.dev/graphql/tools/docs/generate-schema). |
6 | | - |
7 | | -This tool uses [GraphQL Swift](https://github.com/GraphQLSwift/GraphQL) to generate type-safe Swift code and protocol stubs from your GraphQL schema files, eliminating boilerplate while allowing you full control over your business logic. |
| 5 | +A Swift package plugin that generates server-side GraphQL API code from GraphQL schema files, inspired by [GraphQL Tools' makeExecutableSchema](https://the-guild.dev/graphql/tools/docs/generate-schema) and [Swift's OpenAPI Generator](https://github.com/apple/swift-openapi-generator). |
8 | 6 |
|
9 | 7 | ## Features |
10 | 8 |
|
11 | | -- **Build-time code generation**: Code is generated at build time and never needs to be committed |
| 9 | +- **Build-time code generation**: Code is generated at build time and doesn't need to be committed |
12 | 10 | - **Type-safe**: Leverages Swift's type system for compile-time safety |
13 | | -- **Framework-agnostic**: Generated code works with any Swift server framework (Vapor, Hummingbird, etc.) |
14 | | -- **Modern Swift**: Uses async/await for all resolver functions |
15 | | -- **Minimal boilerplate**: Generates only ceremony code - you write the business logic |
| 11 | +- **Minimal boilerplate**: Generates all GraphQL definition code - you write the business logic |
16 | 12 |
|
17 | 13 | ## Installation |
18 | 14 |
|
19 | | -Add the package to your `Package.swift`: |
| 15 | +Add the package to your `Package.swift`. Be sure to add the `GraphQLGeneratorRuntime` dependency to your package, and add the `GraphQLGeneratorPlugin` to the plugins section: |
20 | 16 |
|
21 | 17 | ```swift |
22 | 18 | dependencies: [ |
@@ -78,10 +74,11 @@ Create a resolvers struct with the required typealiases: |
78 | 74 | struct Resolvers: ResolversProtocol { |
79 | 75 | typealias Query = ExamplePackage.Query |
80 | 76 | typealias Mutation = ExamplePackage.Mutation |
| 77 | + typealias Subscription = ExamplePackage.Subscription |
81 | 78 | } |
82 | 79 | ``` |
83 | 80 |
|
84 | | -As you build the `Query` and `Mutation` types and their resolution logic, you will be forced to define a concrete type for every reachable GraphQL result, according to its generated protocol: |
| 81 | +As you build the `Query`, `Mutation`, and `Subscription` types and their resolution logic, you will be forced to define a concrete type for every reachable GraphQL result, according to its generated protocol: |
85 | 82 |
|
86 | 83 | ```swift |
87 | 84 | struct Query: QueryProtocol { |
@@ -218,9 +215,9 @@ public struct EmailAddress: Scalar { |
218 | 215 | ## Development Roadmap |
219 | 216 |
|
220 | 217 | 1. Directives: Directives are currently not supported |
221 | | -2. Subscription: Subscription definitions are currently ignored |
222 | | -3. Improved testing: Generator tests should cover much more of the functionality |
223 | | -4. Additional examples: Ideally large ones that cover significant GraphQL features |
| 218 | +2. Improved testing: Generator tests should cover much more of the functionality |
| 219 | +3. Additional examples: Ideally large ones that cover significant GraphQL features |
| 220 | +4. Enhanced configuration: There should be configuration options for the build plugin itself |
224 | 221 | 5. Executable Schema: To work around the immutability of some Schema components, we generate Swift code to fully recreate the defined schema. Instead, we could just add resolver logic to the schema parsed from the `.graphql` file SDL. |
225 | 222 |
|
226 | 223 | ## Contributing |
|
0 commit comments