Skip to content

Commit 6357451

Browse files
authored
Merge pull request #147 from NeedleInAJayStack/feat/graphql-sdl
2 parents 046675b + 1f35674 commit 6357451

32 files changed

+183
-367
lines changed

MIGRATION.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Migration
2+
3+
## 1.0 to 2.0
4+
5+
### TypeReference removal
6+
7+
The `TypeReference` type was removed in v2.0.0, since it was made unnecessary when using the [GraphQL](https://github.com/GraphQLSwift/GraphQL) closure-based `field` API. Simply replace any `TypeReference` usage with the actual type:
8+
9+
```swift
10+
// Before
11+
let schema = try! Schema<HelloResolver, HelloContext> {
12+
Type(Object1.self) { }
13+
Type(Object2.self) {
14+
Field("object1", at: \.object1, as: TypeReference<Object1>.self)
15+
}
16+
}
17+
18+
// After
19+
let schema = try! Schema<HelloResolver, HelloContext> {
20+
Type(Object1.self) { }
21+
Type(Object2.self) {
22+
Field("object1", at: \.object1)
23+
}
24+
}
25+
```
26+
27+
### Field/InputField `as` argument removal
28+
29+
Since TypeReference was removed, there is no longer a functional need for the `as` argument on `Field` and `InputField`
30+
types. To remove it, simply omit it and let the compiler determine the type from the signature of the `at` argument.
31+
32+
### `Types` removal
33+
34+
The deprecated `Types` type has been removed. Instead define types individually using the `Type` initializers.
35+
36+
### Reflection `isEncodable`
37+
38+
The deprecated `Reflection.isEncodable(type: Any.Type) -> Bool` function has been removed. Please re-implement in your
39+
package if this functionality is needed.

Package.resolved

+47-49
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,50 @@
11
{
2-
"object": {
3-
"pins": [
4-
{
5-
"package": "GraphQL",
6-
"repositoryURL": "https://github.com/GraphQLSwift/GraphQL.git",
7-
"state": {
8-
"branch": null,
9-
"revision": "ec809df8cce95d6aea820f70f04067abc08080f2",
10-
"version": "2.10.3"
11-
}
12-
},
13-
{
14-
"package": "swift-atomics",
15-
"repositoryURL": "https://github.com/apple/swift-atomics.git",
16-
"state": {
17-
"branch": null,
18-
"revision": "cd142fd2f64be2100422d658e7411e39489da985",
19-
"version": "1.2.0"
20-
}
21-
},
22-
{
23-
"package": "swift-collections",
24-
"repositoryURL": "https://github.com/apple/swift-collections",
25-
"state": {
26-
"branch": null,
27-
"revision": "671108c96644956dddcd89dd59c203dcdb36cec7",
28-
"version": "1.1.4"
29-
}
30-
},
31-
{
32-
"package": "swift-nio",
33-
"repositoryURL": "https://github.com/apple/swift-nio.git",
34-
"state": {
35-
"branch": null,
36-
"revision": "914081701062b11e3bb9e21accc379822621995e",
37-
"version": "2.76.1"
38-
}
39-
},
40-
{
41-
"package": "swift-system",
42-
"repositoryURL": "https://github.com/apple/swift-system.git",
43-
"state": {
44-
"branch": null,
45-
"revision": "c8a44d836fe7913603e246acab7c528c2e780168",
46-
"version": "1.4.0"
47-
}
2+
"pins" : [
3+
{
4+
"identity" : "graphql",
5+
"kind" : "remoteSourceControl",
6+
"location" : "https://github.com/GraphQLSwift/GraphQL.git",
7+
"state" : {
8+
"revision" : "5e098b3b1789169dded5116c171f716d584225ea",
9+
"version" : "3.0.0"
4810
}
49-
]
50-
},
51-
"version": 1
11+
},
12+
{
13+
"identity" : "swift-atomics",
14+
"kind" : "remoteSourceControl",
15+
"location" : "https://github.com/apple/swift-atomics.git",
16+
"state" : {
17+
"revision" : "cd142fd2f64be2100422d658e7411e39489da985",
18+
"version" : "1.2.0"
19+
}
20+
},
21+
{
22+
"identity" : "swift-collections",
23+
"kind" : "remoteSourceControl",
24+
"location" : "https://github.com/apple/swift-collections",
25+
"state" : {
26+
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
27+
"version" : "1.1.4"
28+
}
29+
},
30+
{
31+
"identity" : "swift-nio",
32+
"kind" : "remoteSourceControl",
33+
"location" : "https://github.com/apple/swift-nio.git",
34+
"state" : {
35+
"revision" : "f7dc3f527576c398709b017584392fb58592e7f5",
36+
"version" : "2.75.0"
37+
}
38+
},
39+
{
40+
"identity" : "swift-system",
41+
"kind" : "remoteSourceControl",
42+
"location" : "https://github.com/apple/swift-system.git",
43+
"state" : {
44+
"revision" : "c8a44d836fe7913603e246acab7c528c2e780168",
45+
"version" : "1.4.0"
46+
}
47+
}
48+
],
49+
"version" : 2
5250
}

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let package = Package(
77
.library(name: "Graphiti", targets: ["Graphiti"]),
88
],
99
dependencies: [
10-
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "2.10.0"),
10+
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "3.0.0"),
1111
],
1212
targets: [
1313
.target(name: "Graphiti", dependencies: ["GraphQL"]),

Sources/Graphiti/Argument/Argument.swift

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public class Argument<ArgumentsType: Decodable, ArgumentType>: ArgumentComponent
1717
return (name, argument)
1818
}
1919

20+
override func getName() -> String {
21+
return name
22+
}
23+
2024
init(name: String) {
2125
self.name = name
2226
}

Sources/Graphiti/Argument/ArgumentComponent.swift

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ public class ArgumentComponent<ArgumentsType: Decodable> {
99
) throws -> (String, GraphQLArgument) {
1010
fatalError()
1111
}
12+
13+
func getName() -> String {
14+
fatalError()
15+
}
1216
}
1317

1418
public extension ArgumentComponent {

Sources/Graphiti/Component/Component.swift

-22
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ open class Component<Resolver, Context> {
1111
}
1212

1313
func update(typeProvider _: SchemaTypeProvider, coders _: Coders) throws {}
14-
func setGraphQLName(typeProvider _: SchemaTypeProvider) throws {}
1514
}
1615

1716
public extension Component {
@@ -36,25 +35,4 @@ enum ComponentType {
3635
case type
3736
case types
3837
case union
39-
40-
/// An index used to sort components into the correct schema build order. This order goes
41-
/// from "least other type references" to "most". By building in this order we are able to satisfy
42-
/// hard ordering requirements (interfaces MUST be built before inheriting types), as well as
43-
/// reduce unnecessary TypeReferences.
44-
var buildOrder: Int {
45-
switch self {
46-
case .none: return 0
47-
case .scalar: return 1
48-
case .enum: return 2
49-
case .interface: return 3
50-
case .input: return 4
51-
case .connection: return 5
52-
case .type: return 6
53-
case .types: return 7
54-
case .union: return 8
55-
case .query: return 9
56-
case .mutation: return 10
57-
case .subscription: return 11
58-
}
59-
}
6038
}

Sources/Graphiti/Definition/Reflection.swift

-13
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,6 @@ public enum Reflection {
44
return description.hasSuffix("Protocol")
55
}
66

7-
@available(*, deprecated, message: "No longer used")
8-
public static func isEncodable(type: Any.Type) -> Bool {
9-
if isProtocol(type: type) {
10-
return true
11-
}
12-
13-
if let type = type as? Wrapper.Type {
14-
return isEncodable(type: type.wrappedType)
15-
}
16-
17-
return type is Encodable.Type
18-
}
19-
207
public static func name<Subject>(for instance: Subject) -> String {
218
var typeName: [Character] = []
229
var genericArgument: [Character] = []

Sources/Graphiti/Definition/TypeProvider.swift

+3-13
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,12 @@ extension TypeProvider {
6666
from: GraphQLList(graphQLType),
6767
isOptional: isOptional
6868
)
69-
case .reference:
70-
let name = getGraphQLName(of: type.wrappedType)
71-
let referenceType = GraphQLTypeReference(name)
72-
73-
return try getGraphQLOptionalType(from: referenceType, isOptional: isOptional)
7469
}
7570
} else {
76-
if let graphQLType = graphQLTypeMap[AnyType(type)] {
77-
return try getGraphQLOptionalType(from: graphQLType, isOptional: isOptional)
78-
} else {
79-
// If we haven't seen this type yet, just store it as a type reference and resolve later.
80-
let name = getGraphQLName(of: type)
81-
let referenceType = GraphQLTypeReference(name)
82-
83-
return try getGraphQLOptionalType(from: referenceType, isOptional: isOptional)
71+
guard let graphQLType = graphQLTypeMap[AnyType(type)] else {
72+
throw GraphQLError(message: "Type not found \(type).")
8473
}
74+
return try getGraphQLOptionalType(from: graphQLType, isOptional: isOptional)
8575
}
8676
}
8777

Sources/Graphiti/Definition/TypeReference.swift

-11
This file was deleted.

Sources/Graphiti/Definition/Wrappers.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
enum WrapperModifier {
22
case optional
33
case list
4-
case reference
54
}
65

76
protocol Wrapper {

Sources/Graphiti/Enum/Enum.swift

-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ public final class Enum<
2626
try typeProvider.add(type: EnumType.self, as: enumType)
2727
}
2828

29-
override func setGraphQLName(typeProvider: SchemaTypeProvider) throws {
30-
try typeProvider.mapName(EnumType.self, to: name)
31-
}
32-
3329
private init(
3430
type _: EnumType.Type,
3531
name: String?,

Sources/Graphiti/Federation/Key/Key.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ public class Key<ObjectType, Resolver, Context, Arguments: Codable>: KeyComponen
2626
}
2727

2828
override func validate(
29-
againstFields fieldNames: [String],
30-
typeProvider: TypeProvider,
31-
coders: Coders
29+
againstFields fieldNames: [String]
3230
) throws {
3331
// Ensure that every argument is included in the provided field list
34-
for (name, _) in try arguments(typeProvider: typeProvider, coders: coders) {
32+
for name in arguments.map({ $0.getName() }) {
3533
if !fieldNames.contains(name) {
3634
throw GraphQLError(message: "Argument name not found in type fields: \(name)")
3735
}

Sources/Graphiti/Federation/Key/KeyComponent.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ public class KeyComponent<ObjectType, Resolver, Context> {
1717
}
1818

1919
func validate(
20-
againstFields _: [String],
21-
typeProvider _: TypeProvider,
22-
coders _: Coders
20+
againstFields _: [String]
2321
) throws {
2422
fatalError()
2523
}

0 commit comments

Comments
 (0)