Skip to content

Commit a389c8c

Browse files
chore: Deletes AI cruft
1 parent e4fba9a commit a389c8c

3 files changed

Lines changed: 51 additions & 144 deletions

File tree

Package.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// swift-tools-version: 6.2
2-
// The swift-tools-version declares the minimum version of Swift required to build this package.
1+
// swift-tools-version: 6.0
32

43
import PackageDescription
54

README.md

Lines changed: 50 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,8 @@
11
# GraphQL Generator for Swift
22

3-
A Swift package plugin that generates server-side GraphQL API code from GraphQL schema files, inspired by [swift-openapi-generator](https://github.com/apple/swift-openapi-generator).
3+
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).
44

5-
This tool uses [GraphQL Swift](https://github.com/GraphQLSwift/GraphQL) to generate type-safe Swift code from your GraphQL schemas, eliminating boilerplate while maintaining full control over your business logic.
6-
7-
## Status
8-
9-
🚧 **Phase 1 Complete** - Foundation is in place with basic code generation
10-
11-
Currently implemented:
12-
- ✅ Build plugin for SPM integration
13-
- ✅ GraphQL schema parsing using GraphQL Swift's `buildSchema`
14-
- ✅ Type generation (Swift structs from GraphQL types)
15-
- ✅ Resolver protocol generation
16-
- ✅ Basic runtime library with ResolverContext
17-
- ✅ CLI tool for code generation
18-
19-
Still in development (see [plan.md](plan.md)):
20-
- ⏳ Complete schema builder generation (Phase 5)
21-
- ⏳ Mutations and subscriptions support
22-
- ⏳ Custom scalar mappings
23-
- ⏳ Configuration file support
24-
- ⏳ Complete test coverage
25-
- ⏳ Working end-to-end examples
5+
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 maintaining full control over your business logic.
266

277
## Features
288

@@ -32,20 +12,14 @@ Still in development (see [plan.md](plan.md)):
3212
- **Modern Swift**: Uses async/await for all resolver functions
3313
- **Minimal boilerplate**: Generates only ceremony code - you write the business logic
3414

35-
## Requirements
36-
37-
- Swift 6.2+
38-
- macOS 13+, iOS 16+, tvOS 16+, or watchOS 9+
39-
- GraphQL Swift 4.0+
40-
4115
## Installation
4216

4317
Add the package to your `Package.swift`:
4418

4519
```swift
4620
dependencies: [
4721
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "4.0.0"),
48-
.package(url: "https://github.com/YourOrg/graphql-generator", from: "1.0.0")
22+
.package(url: "https://github.com/GraphQLSwift/graphql-generator", from: "1.0.0")
4923
],
5024
targets: [
5125
.target(
@@ -84,143 +58,78 @@ type Query {
8458
### 2. Build Your Project
8559

8660
When you build, the plugin will automatically generate Swift code:
87-
- `Types.swift` - Swift structs for your GraphQL types
88-
- `Resolvers.swift` - Protocol defining resolver methods
89-
- `Schema.swift` - Schema builder (coming in Phase 5)
61+
- `Types.swift` - Swift protocols for your GraphQL types
62+
- `Schema.swift` - Schema
9063

91-
### 3. Implement the Resolver Protocol
64+
### 3. Create required types
9265

93-
```swift
94-
import GraphQL
95-
import GraphQLGeneratorRuntime
96-
97-
struct MyResolvers: GraphQLResolvers {
98-
func user(id: String, context: ResolverContext) async throws -> User? {
99-
// Your business logic here
100-
return User(id: id, name: "John Doe", email: "john@example.com")
101-
}
66+
Create a type named `Context`:
10267

103-
func users(context: ResolverContext) async throws -> [User] {
104-
// Your business logic here
105-
return [
106-
User(id: "1", name: "Alice", email: "alice@example.com"),
107-
User(id: "2", name: "Bob", email: "bob@example.com"),
108-
]
109-
}
68+
```swift
69+
public actor Context {
70+
// Add any features you like
11071
}
11172
```
11273

113-
### 4. Execute GraphQL Queries
74+
Create any scalar types (with names matching GraphQL), and conform them to `Scalar`:
11475

11576
```swift
116-
import GraphQL
117-
118-
// Create resolvers
119-
let resolvers = MyResolvers()
120-
121-
// Build schema (Phase 5 - not yet implemented)
122-
// let schema = try buildGraphQLSchema(resolvers: resolvers)
123-
124-
// Execute a query
125-
// let result = try await graphql(schema: schema, request: "{ users { name email } }")
126-
// print(result)
127-
```
128-
129-
## Project Structure
130-
131-
```
132-
graphql-generator/
133-
├── Package.swift
134-
├── README.md
135-
├── plan.md # Detailed implementation plan
136-
├── Plugins/
137-
│ └── GraphQLGeneratorPlugin.swift # SPM build plugin
138-
├── Sources/
139-
│ ├── GraphQLGenerator/ # CLI executable
140-
│ ├── GraphQLGeneratorCore/ # Parsing and generation logic
141-
│ │ ├── Parser/
142-
│ │ │ └── SchemaParser.swift
143-
│ │ └── Generator/
144-
│ │ ├── CodeGenerator.swift
145-
│ │ ├── TypeGenerator.swift
146-
│ │ ├── ResolverGenerator.swift
147-
│ │ └── SchemaGenerator.swift
148-
│ └── GraphQLGeneratorRuntime/ # Runtime support library
149-
│ └── ResolverContext.swift
150-
├── Tests/
151-
│ └── GraphQLGeneratorTests/
152-
└── Examples/
153-
└── HelloWorldServer/
77+
struct DateTime: Scalar {}
15478
```
15579

156-
## Generated Code Examples
157-
158-
### From this GraphQL schema:
159-
160-
```graphql
161-
type User {
162-
id: ID!
163-
name: String!
164-
email: String!
80+
Create a resolvers struct with the required typealiases:
81+
```swift
82+
struct Resolvers: ResolversProtocol {
83+
typealias Query = ExamplePackage.Query
84+
typealias Mutation = ExamplePackage.Mutation
16585
}
16686
```
16787

168-
### Generates this Swift code:
88+
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.
89+
Here's a small example of a schema that allows querying for the current user, who is only identified by an email address:
16990

17091
```swift
171-
// Types.swift
172-
public struct User: Codable {
173-
public let id: String
174-
public let name: String
175-
public let email: String
176-
177-
public init(
178-
id: String,
179-
name: String,
180-
email: String
181-
) {
182-
self.id = id
183-
self.name = name
184-
self.email = email
92+
struct Query: QueryProtocol {
93+
// This is required by `QueryProtocol`, and used by GraphQL query resolution.
94+
static func user(context: Context, info: GraphQLResolveInfo) async throws -> (any UserProtocol)? {
95+
// You can implement resolution logic however you like.
96+
return context.user
18597
}
18698
}
18799

188-
// Resolvers.swift
189-
public protocol GraphQLResolvers {
190-
func user(id: String, context: ResolverContext) async throws -> User?
191-
func users(context: ResolverContext) async throws -> [User]
100+
struct User: UserProtocol {
101+
// You can define the type internals however you like
102+
let email: String
103+
104+
// This is required by `UserProtocol`, and used by GraphQL field resolution.
105+
func email(context: Context, info: GraphQL.GraphQLResolveInfo) async throws -> String {
106+
// You can implement resolution logic however you like.
107+
return email
108+
}
192109
}
193110
```
194111

195-
## Development Roadmap
196-
197-
See [plan.md](plan.md) for the complete implementation plan across 8 phases:
198-
199-
- **Phase 1: Foundation** ✅ - Basic infrastructure and plugin setup
200-
- **Phase 2: Schema Parsing** - Complete SDL parsing (in progress)
201-
- **Phase 3: Type Generation** - Full type generation with all GraphQL constructs
202-
- **Phase 4: Resolver Generation** - Complete resolver protocol generation
203-
- **Phase 5: Schema Builder** - Generate executable GraphQL schema
204-
- **Phase 6: Advanced Features** - Mutations, subscriptions, custom scalars
205-
- **Phase 7: Runtime & Ergonomics** - Helper utilities and patterns
206-
- **Phase 8: Examples & Documentation** - Complete examples and guides
207-
208-
## Contributing
112+
### 4. Execute GraphQL Queries
209113

210-
This project is in active development. Contributions are welcome!
114+
```swift
115+
import GraphQL
211116

212-
## License
117+
let schema = try buildGraphQLSchema(resolvers: Resolvers.self)
213118

214-
TBD
119+
// Execute a query
120+
let result = try await graphql(schema: schema, request: "{ users { name email } }")
121+
print(result)
122+
```
215123

216-
## Inspiration
124+
## Development Roadmap
217125

218-
This project is inspired by:
219-
- [swift-openapi-generator](https://github.com/apple/swift-openapi-generator) - Build plugin architecture
220-
- [GraphQL Swift](https://github.com/GraphQLSwift/GraphQL) - Runtime GraphQL implementation
126+
1. Default values: Default values are currently ignored
127+
2. Directives: Directives are currently not supported
128+
3. Subscription: Subscription definitions are currently ignored
129+
4. Improved testing: Generator tests should cover much more of the functionality
130+
5. Additional examples: Ideally large ones that cover significant GraphQL features
131+
6. 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.
221132

222-
## Related Projects
133+
## Contributing
223134

224-
- [GraphQL Swift](https://github.com/GraphQLSwift/GraphQL) - The Swift GraphQL implementation
225-
- [Vapor](https://github.com/vapor/vapor) - Server-side Swift framework
226-
- [Hummingbird](https://github.com/hummingbird-project/hummingbird) - Lightweight server framework
135+
This project is in active development. Contributions are welcome!

Tests/GraphQLGeneratorTests/PlaceholderTests.swift

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)