You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat!: Scalars are namespaced inside GraphQLScalars
This will prevent type name collisions. In some common schemas, we were already hitting name collisions between custom scalars and Foundation types (Like `Date` and `URL`).
Copy file name to clipboardExpand all lines: README.md
+40-40Lines changed: 40 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,11 +68,11 @@ actor GraphQLContext {
68
68
}
69
69
```
70
70
71
-
Create any scalar types (with names matching GraphQL), and conform them to `GraphQLScalar`. See the `Scalars` usage section below for details.
71
+
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.
72
72
73
73
Create a resolvers struct with the required typealiases:
// You can implement resolution logic however you like.
104
-
returnEmailAddress(email: self.email)
104
+
return.init(email: self.email)
105
105
}
106
106
}
107
107
```
@@ -123,7 +123,7 @@ print(result)
123
123
All generated types other than `GraphQLContext` and scalar types are namespaced inside of `GraphQLGenerated` to minimize polluting the inheriting package's type namespace.
124
124
125
125
### Root Types
126
-
Root types (Query, Mutation, and Subscription) are modeled as Swift protocols with static method requirements for each field. The user must implement these types and provide them to the `buildGraphQLSchema` function.
126
+
Root types (Query, Mutation, and Subscription) are modeled as Swift protocols with static method requirements for each field. The user must implement these types and provide them to the `buildGraphQLSchema` function via the `Resolvers` typealiases.
127
127
128
128
### Object Types
129
129
Object types are modeled as Swift protocols with instance method requirements for each field. This is to enable maximum implementation flexibility. Internally, GraphQL passes result objects directly through to subsequent resolvers. By only specifying the interface, we allow the backing types to be incredibly dynamic - they can be simple codable structs or complex stateful actors, reference or values types, or any other type configuration.
@@ -166,52 +166,52 @@ Interfaces are modeled as a protocol with required methods for each relevant fie
166
166
Union types are modeled as a marker protocol, with no required properties or functions. Related objects are marked as requiring conformance to the union protocol.
167
167
168
168
### Input Object Types
169
-
Input object types are modeled as a deterministic Codable struct with the declared fields. If more complex objects must be created from the codable struct, this can be done in the resolver itself, since input objects only relevant for their associated resolver (they are not passed to downstream resolvers).
169
+
Input object types are modeled as a deterministic Codable struct with the declared fields. If more complex objects must be created from the codable struct, this can be done in the resolver itself, since input objects are only relevant for their associated resolver (they are not passed to downstream resolvers).
170
170
171
171
### Enum Types
172
172
Enum types are modeled as a deterministic String enum with values matching the declared fields and associated representations. If you need different values or more complex implementations, simply convert to/from a different representation inside your resolvers.
173
173
174
174
### Scalar Types
175
-
Scalar types are not modeled by the generator. They are simply referenced using the Scalar's name, and you are expected to implement the required type. Since GraphQL uses a different serialization system than Swift, you must conform the type to Swift's `Codable` and GraphQL's `GraphQLScalar`, and have them agree on a representation.
176
-
177
-
Below is an example that represents a scalar struct as a raw String:
175
+
Scalar types are not modeled by the generator. They are simply referenced as `GraphQLScalars.<name>`, and you are expected to implement the required type, and conform it to `GraphQLScalar`. Since GraphQL uses a different serialization system than Swift, you should be sure that the type's conformance to Swift's `Codable` and GraphQL's `GraphQLScalar` agree on a representation. Below is an example that represents a scalar struct as a raw String:
178
176
179
177
```swift
180
-
structEmailAddress: GraphQLScalar {
181
-
let email: String
178
+
extensionGraphQLScalars {
179
+
structEmailAddress: GraphQLScalar {
180
+
let email: String
182
181
183
-
init(email: String) {
184
-
self.email= email
185
-
}
182
+
init(email: String) {
183
+
self.email= email
184
+
}
186
185
187
-
// Codability conformance. Represent simply as `email` string.
0 commit comments