Skip to content

Commit

Permalink
Merge pull request #147 from NeedleInAJayStack/feat/graphql-sdl
Browse files Browse the repository at this point in the history
  • Loading branch information
paulofaria authored Dec 14, 2024
2 parents 046675b + 1f35674 commit 6357451
Show file tree
Hide file tree
Showing 32 changed files with 183 additions and 367 deletions.
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
Original file line number Diff line number Diff line change
@@ -1,52 +1,50 @@
{
"object": {
"pins": [
{
"package": "GraphQL",
"repositoryURL": "https://github.com/GraphQLSwift/GraphQL.git",
"state": {
"branch": null,
"revision": "ec809df8cce95d6aea820f70f04067abc08080f2",
"version": "2.10.3"
}
},
{
"package": "swift-atomics",
"repositoryURL": "https://github.com/apple/swift-atomics.git",
"state": {
"branch": null,
"revision": "cd142fd2f64be2100422d658e7411e39489da985",
"version": "1.2.0"
}
},
{
"package": "swift-collections",
"repositoryURL": "https://github.com/apple/swift-collections",
"state": {
"branch": null,
"revision": "671108c96644956dddcd89dd59c203dcdb36cec7",
"version": "1.1.4"
}
},
{
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "914081701062b11e3bb9e21accc379822621995e",
"version": "2.76.1"
}
},
{
"package": "swift-system",
"repositoryURL": "https://github.com/apple/swift-system.git",
"state": {
"branch": null,
"revision": "c8a44d836fe7913603e246acab7c528c2e780168",
"version": "1.4.0"
}
"pins" : [
{
"identity" : "graphql",
"kind" : "remoteSourceControl",
"location" : "https://github.com/GraphQLSwift/GraphQL.git",
"state" : {
"revision" : "5e098b3b1789169dded5116c171f716d584225ea",
"version" : "3.0.0"
}
]
},
"version": 1
},
{
"identity" : "swift-atomics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-atomics.git",
"state" : {
"revision" : "cd142fd2f64be2100422d658e7411e39489da985",
"version" : "1.2.0"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
"version" : "1.1.4"
}
},
{
"identity" : "swift-nio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "f7dc3f527576c398709b017584392fb58592e7f5",
"version" : "2.75.0"
}
},
{
"identity" : "swift-system",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-system.git",
"state" : {
"revision" : "c8a44d836fe7913603e246acab7c528c2e780168",
"version" : "1.4.0"
}
}
],
"version" : 2
}
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

0 comments on commit 6357451

Please sign in to comment.