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
7 changes: 7 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": 1,
"indentation" : {
"spaces" : 4
},
"lineBreakBeforeEachArgument": true
}
14 changes: 9 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ let package = Package(
name: "Graphiti",
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)],
products: [
.library(name: "Graphiti", targets: ["Graphiti"]),
.library(name: "Graphiti", targets: ["Graphiti"])
],
dependencies: [
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "4.0.0"),
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "4.0.0")
],
targets: [
.target(name: "Graphiti", dependencies: ["GraphQL"]),
.testTarget(name: "GraphitiTests", dependencies: ["Graphiti"], resources: [
.copy("FederationTests/GraphQL"),
]),
.testTarget(
name: "GraphitiTests",
dependencies: ["Graphiti"],
resources: [
.copy("FederationTests/GraphQL")
]
),
],
swiftLanguageVersions: [.v5, .version("6")]
)
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ This package supports Swift versions in [alignment with Swift NIO](https://githu

## Contributing

This repo uses [SwiftFormat](https://github.com/nicklockwood/SwiftFormat), and includes lint checks to enforce these formatting standards.
To format your code, install `swiftformat` and run:
This repo uses the standard [swift format](https://github.com/swiftlang/swift-format), and includes lint checks to enforce these formatting standards.
To format your code, run:

```bash
swiftformat .
swift format --parallel --in-place --recursive ./
```

## License
Expand Down
10 changes: 5 additions & 5 deletions Sources/Graphiti/API/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public protocol API {
var schema: Schema<Resolver, ContextType> { get }
}

public extension API {
func execute(
extension API {
public func execute(
request: String,
context: ContextType,
variables: [String: Map] = [:],
Expand All @@ -25,7 +25,7 @@ public extension API {
)
}

func execute(
public func execute(
request: GraphQLRequest,
context: ContextType,
validationRules: [@Sendable (ValidationContext) -> Visitor] = []
Expand All @@ -39,7 +39,7 @@ public extension API {
)
}

func subscribe(
public func subscribe(
request: String,
context: ContextType,
variables: [String: Map] = [:],
Expand All @@ -56,7 +56,7 @@ public extension API {
)
}

func subscribe(
public func subscribe(
request: GraphQLRequest,
context: ContextType,
validationRules: [@Sendable (ValidationContext) -> Visitor] = []
Expand Down
8 changes: 4 additions & 4 deletions Sources/Graphiti/Argument/Argument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ public class Argument<ArgumentsType: Decodable, ArgumentType>: ArgumentComponent
}
}

public extension Argument {
convenience init(
extension Argument {
public convenience init(
_ name: String,
at _: KeyPath<ArgumentsType, ArgumentType>
) {
self.init(name: name)
}
}

public extension Argument where ArgumentType: Encodable {
func defaultValue(_ defaultValue: ArgumentType) -> Self {
extension Argument where ArgumentType: Encodable {
public func defaultValue(_ defaultValue: ArgumentType) -> Self {
self.defaultValue = AnyEncodable(defaultValue)
return self
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Graphiti/Argument/ArgumentComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class ArgumentComponent<ArgumentsType: Decodable> {
}
}

public extension ArgumentComponent {
func description(_ description: String) -> Self {
extension ArgumentComponent {
public func description(_ description: String) -> Self {
self.description = description
return self
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Graphiti/Component/Component.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ open class Component<Resolver: Sendable, Context: Sendable> {
func update(typeProvider _: SchemaTypeProvider, coders _: Coders) throws {}
}

public extension Component {
func description(_ description: String) -> Self {
extension Component {
public func description(_ description: String) -> Self {
self.description = description
return self
}
Expand Down
42 changes: 21 additions & 21 deletions Sources/Graphiti/Connection/Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,36 @@ public struct Connection<Node: Sendable>: Sendable {
public let pageInfo: PageInfo
}

public extension Connection where Node: Identifiable, Node.ID: LosslessStringConvertible {
static func id(_ cursor: String) -> Node.ID? {
extension Connection where Node: Identifiable, Node.ID: LosslessStringConvertible {
public static func id(_ cursor: String) -> Node.ID? {
cursor.base64Decoded().flatMap { Node.ID($0) }
}

static func cursor(_ node: Node) -> String {
public static func cursor(_ node: Node) -> String {
node.id.description.base64Encoded()!
}
}

public extension Sequence where Element: Sendable, Element: Identifiable,
Element.ID: LosslessStringConvertible {
func connection(from arguments: Paginatable) throws -> Connection<Element> {
extension Sequence
where
Element: Sendable, Element: Identifiable,
Element.ID: LosslessStringConvertible
{
public func connection(from arguments: Paginatable) throws -> Connection<Element> {
try connection(from: arguments, makeCursor: Connection<Element>.cursor)
}

func connection(from arguments: ForwardPaginatable) throws -> Connection<Element> {
public func connection(from arguments: ForwardPaginatable) throws -> Connection<Element> {
try connection(from: arguments, makeCursor: Connection<Element>.cursor)
}

func connection(from arguments: BackwardPaginatable) throws -> Connection<Element> {
public func connection(from arguments: BackwardPaginatable) throws -> Connection<Element> {
try connection(from: arguments, makeCursor: Connection<Element>.cursor)
}
}

public extension Sequence where Element: Sendable {
func connection(
extension Sequence where Element: Sendable {
public func connection(
from arguments: Paginatable,
makeCursor: @escaping (Element) throws -> String
) throws -> Connection<Element> {
Expand All @@ -43,7 +46,7 @@ public extension Sequence where Element: Sendable {
)
}

func connection(
public func connection(
from arguments: ForwardPaginatable,
makeCursor: @escaping (Element) throws -> String
) throws -> Connection<Element> {
Expand All @@ -54,7 +57,7 @@ public extension Sequence where Element: Sendable {
)
}

func connection(
public func connection(
from arguments: BackwardPaginatable,
makeCursor: @escaping (Element) throws -> String
) throws -> Connection<Element> {
Expand Down Expand Up @@ -96,19 +99,16 @@ func slicingCursor<Node>(
) -> ArraySlice<Edge<Node>> {
var edges = ArraySlice(edges)

if
let after = arguments.after,
let afterIndex = edges
.firstIndex(where: { $0.cursor == after })?
.advanced(by: 1)
if let after = arguments.after,
let afterIndex =
edges.firstIndex(where: { $0.cursor == after })?.advanced(by: 1)
{
edges = edges[afterIndex...]
}

if
let before = arguments.before,
let beforeIndex = edges
.firstIndex(where: { $0.cursor == before })
if let before = arguments.before,
let beforeIndex =
edges.firstIndex(where: { $0.cursor == before })
{
edges = edges[..<beforeIndex]
}
Expand Down
9 changes: 3 additions & 6 deletions Sources/Graphiti/Connection/ConnectionType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ public final class ConnectionType<
Resolver: Sendable,
Context: Sendable,
ObjectType: Sendable
>: TypeComponent<
Resolver,
Context
> {
>: TypeComponent<Resolver, Context> {
override func update(typeProvider: SchemaTypeProvider, coders: Coders) throws {
if !typeProvider.contains(type: PageInfo.self) {
let pageInfo = Type<Resolver, Context, PageInfo>(PageInfo.self) {
Expand Down Expand Up @@ -52,8 +49,8 @@ public final class ConnectionType<
}
}

public extension ConnectionType {
convenience init(
extension ConnectionType {
public convenience init(
_ type: ObjectType.Type,
as name: String? = nil
) {
Expand Down
Loading
Loading