Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Migration

## 1.0 to 2.0

### TypeReference removal

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:

```swift
// Before
let schema = try! Schema<HelloResolver, HelloContext> {
Type(Object1.self) { }
Type(Object2.self) {
Field("object1", at: \.object1, as: TypeReference<Object1>.self)
}
}

// After
let schema = try! Schema<HelloResolver, HelloContext> {
Type(Object1.self) { }
Type(Object2.self) {
Field("object1", at: \.object1)
}
}
```

### Field/InputField `as` argument removal

Since TypeReference was removed, there is no longer a functional need for the `as` argument on `Field` and `InputField`
types. To remove it, simply omit it and let the compiler determine the type from the signature of the `at` argument.

### `Types` removal

The deprecated `Types` type has been removed. Instead define types individually using the `Type` initializers.

### Reflection `isEncodable`

The deprecated `Reflection.isEncodable(type: Any.Type) -> Bool` function has been removed. Please re-implement in your
package if this functionality is needed.
96 changes: 47 additions & 49 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let package = Package(
.library(name: "Graphiti", targets: ["Graphiti"]),
],
dependencies: [
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "2.10.0"),
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "3.0.0"),
],
targets: [
.target(name: "Graphiti", dependencies: ["GraphQL"]),
Expand Down
4 changes: 4 additions & 0 deletions Sources/Graphiti/Argument/Argument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public class Argument<ArgumentsType: Decodable, ArgumentType>: ArgumentComponent
return (name, argument)
}

override func getName() -> String {
return name
}

init(name: String) {
self.name = name
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/Graphiti/Argument/ArgumentComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public class ArgumentComponent<ArgumentsType: Decodable> {
) throws -> (String, GraphQLArgument) {
fatalError()
}

func getName() -> String {
fatalError()
}
}

public extension ArgumentComponent {
Expand Down
22 changes: 0 additions & 22 deletions Sources/Graphiti/Component/Component.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ open class Component<Resolver, Context> {
}

func update(typeProvider _: SchemaTypeProvider, coders _: Coders) throws {}
func setGraphQLName(typeProvider _: SchemaTypeProvider) throws {}
}

public extension Component {
Expand All @@ -36,25 +35,4 @@ enum ComponentType {
case type
case types
case union

/// An index used to sort components into the correct schema build order. This order goes
/// from "least other type references" to "most". By building in this order we are able to satisfy
/// hard ordering requirements (interfaces MUST be built before inheriting types), as well as
/// reduce unnecessary TypeReferences.
var buildOrder: Int {
switch self {
case .none: return 0
case .scalar: return 1
case .enum: return 2
case .interface: return 3
case .input: return 4
case .connection: return 5
case .type: return 6
case .types: return 7
case .union: return 8
case .query: return 9
case .mutation: return 10
case .subscription: return 11
}
}
}
13 changes: 0 additions & 13 deletions Sources/Graphiti/Definition/Reflection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,6 @@ public enum Reflection {
return description.hasSuffix("Protocol")
}

@available(*, deprecated, message: "No longer used")
public static func isEncodable(type: Any.Type) -> Bool {
if isProtocol(type: type) {
return true
}

if let type = type as? Wrapper.Type {
return isEncodable(type: type.wrappedType)
}

return type is Encodable.Type
}

public static func name<Subject>(for instance: Subject) -> String {
var typeName: [Character] = []
var genericArgument: [Character] = []
Expand Down
16 changes: 3 additions & 13 deletions Sources/Graphiti/Definition/TypeProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,12 @@ extension TypeProvider {
from: GraphQLList(graphQLType),
isOptional: isOptional
)
case .reference:
let name = getGraphQLName(of: type.wrappedType)
let referenceType = GraphQLTypeReference(name)

return try getGraphQLOptionalType(from: referenceType, isOptional: isOptional)
}
} else {
if let graphQLType = graphQLTypeMap[AnyType(type)] {
return try getGraphQLOptionalType(from: graphQLType, isOptional: isOptional)
} else {
// If we haven't seen this type yet, just store it as a type reference and resolve later.
let name = getGraphQLName(of: type)
let referenceType = GraphQLTypeReference(name)

return try getGraphQLOptionalType(from: referenceType, isOptional: isOptional)
guard let graphQLType = graphQLTypeMap[AnyType(type)] else {
throw GraphQLError(message: "Type not found \(type).")
}
return try getGraphQLOptionalType(from: graphQLType, isOptional: isOptional)
}
}

Expand Down
11 changes: 0 additions & 11 deletions Sources/Graphiti/Definition/TypeReference.swift

This file was deleted.

1 change: 0 additions & 1 deletion Sources/Graphiti/Definition/Wrappers.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
enum WrapperModifier {
case optional
case list
case reference
}

protocol Wrapper {
Expand Down
4 changes: 0 additions & 4 deletions Sources/Graphiti/Enum/Enum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public final class Enum<
try typeProvider.add(type: EnumType.self, as: enumType)
}

override func setGraphQLName(typeProvider: SchemaTypeProvider) throws {
try typeProvider.mapName(EnumType.self, to: name)
}

private init(
type _: EnumType.Type,
name: String?,
Expand Down
6 changes: 2 additions & 4 deletions Sources/Graphiti/Federation/Key/Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ public class Key<ObjectType, Resolver, Context, Arguments: Codable>: KeyComponen
}

override func validate(
againstFields fieldNames: [String],
typeProvider: TypeProvider,
coders: Coders
againstFields fieldNames: [String]
) throws {
// Ensure that every argument is included in the provided field list
for (name, _) in try arguments(typeProvider: typeProvider, coders: coders) {
for name in arguments.map({ $0.getName() }) {
if !fieldNames.contains(name) {
throw GraphQLError(message: "Argument name not found in type fields: \(name)")
}
Expand Down
4 changes: 1 addition & 3 deletions Sources/Graphiti/Federation/Key/KeyComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public class KeyComponent<ObjectType, Resolver, Context> {
}

func validate(
againstFields _: [String],
typeProvider _: TypeProvider,
coders _: Coders
againstFields _: [String]
) throws {
fatalError()
}
Expand Down
Loading