Skip to content

Commit 659d83b

Browse files
docs: Minor documentation improvements
1 parent 39bea09 commit 659d83b

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
# GraphQL Generator for Swift
44

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).
5+
This is 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).
66

77
## Features
88

9-
- **Data-driven**: Guarantee conformance with declared GraphQL spec
9+
- **Data-driven**: Guarantee conformance with the declared GraphQL spec
1010
- **Build-time code generation**: Code is generated at build time and doesn't need to be committed
1111
- **Type-safe**: Leverages Swift's type system for compile-time safety
1212
- **Minimal boilerplate**: Generates all GraphQL definition code - you write the business logic
@@ -37,6 +37,8 @@ targets: [
3737

3838
## Quick Start
3939

40+
*Protip*: Take a look at the projects in the `Examples` directory to see real, fully featured examples.
41+
4042
### 1. Create a GraphQL Schema
4143

4244
Create a `.graphql` file in your target's `Sources` directory:
@@ -55,7 +57,7 @@ type Query {
5557

5658
### 2. Build Your Project
5759

58-
When you build, the plugin will automatically generate Swift code that you can view in the `.build/plugins/outputs` directory:
60+
When you build, the plugin will automatically generate Swift code. If you want, you can view it in the `.build/plugins/outputs` directory:
5961
- `BuildGraphQLSchema.swift` - Defines `buildGraphQLSchema` function that builds an executable schema.
6062
- `GraphQLRawSDL.swift` - The `graphQLRawSDL` global property, which is a Swift string literal of the input schema. This is internally used at runtime to parse the schema.
6163
- `GraphQLTypes.swift` - Swift protocols and types for your GraphQL types. These are all namespaced within `GraphQLGenerated`.
@@ -72,7 +74,7 @@ actor GraphQLContext {
7274

7375
If your schema has any custom scalar types, you must create them manually in the `GraphQLScalars` namespace. See the `Scalars` usage section below for details.
7476

75-
Create a resolvers struct with the required typealiases:
77+
Create a struct that conforms to `GraphQLGenerated.Resolvers` by defining the required typealiases:
7678
```swift
7779
struct Resolvers: GraphQLGenerated.Resolvers {
7880
typealias Query = ExamplePackage.Query
@@ -108,16 +110,20 @@ struct User: GraphQLGenerated.User {
108110
}
109111
```
110112

113+
Let the protocol conformance guide you on what resolver methods your types must define, and keep going until everything compiles.
114+
111115
### 4. Execute GraphQL Queries
112116

117+
You're done! You can now instantiate your GraphQL schema by calling `buildGraphQLSchema`, and run queries against it:
118+
113119
```swift
114120
import GraphQL
115121

116122
// Build the auto-generated schema
117123
let schema = try buildGraphQLSchema(resolvers: Resolvers.self)
118124

119125
// Execute a query against it
120-
let result = try await graphql(schema: schema, request: "{ users { name email } }")
126+
let result = try await graphql(schema: schema, request: "{ users { name email } }", context: GraphQLContext())
121127
print(result)
122128
```
123129

@@ -138,7 +144,7 @@ type A {
138144
}
139145
```
140146

141-
This would result in the following protocol:
147+
This would result in the following generated protocol:
142148
```swift
143149
protocol A: Sendable {
144150
func foo(context: GraphQLContext, info: GraphQLResolveInfo) async throws -> String

0 commit comments

Comments
 (0)