Skip to content

Commit

Permalink
Merge pull request #109 from NeedleInAJayStack/fix/connection-name
Browse files Browse the repository at this point in the history
Fixes connection processing order
  • Loading branch information
NeedleInAJayStack authored Mar 13, 2023
2 parents b17c86b + d4187e1 commit 64b180e
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Sources/Graphiti/Component/Component.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ enum ComponentType {
case .enum: return 2
case .interface: return 3
case .input: return 4
case .type: return 5
case .types: return 6
case .union: return 7
case .connection: return 8
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
Expand Down
92 changes: 92 additions & 0 deletions Tests/GraphitiTests/ConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -463,4 +463,96 @@ class ConnectionTests: XCTestCase {
)
)
}

/// Test that adjusting names using `as` works
func testNaming() throws {
struct ChatObject: Codable {
func messages(
context _: NoContext,
arguments: PaginationArguments
) throws -> Connection<MessageObject> {
return try [
MessageObject(id: 1, text: "a"),
MessageObject(id: 2, text: "b"),
].connection(from: arguments)
}
}

struct MessageObject: Codable, Identifiable {
let id: Int
let text: String
}

struct Resolver {
func chatObject(context _: NoContext, arguments _: NoArguments) throws -> ChatObject {
return ChatObject()
}
}

let schema = try Schema<Resolver, NoContext> {
Type(ChatObject.self, as: "Chat") {
Field("messages", at: ChatObject.messages, as: Connection<MessageObject>.self) {
Argument("first", at: \.first)
Argument("after", at: \.after)
Argument("last", at: \.last)
Argument("before", at: \.before)
}
}

Type(MessageObject.self, as: "Message") {
Field("id", at: \.id)
Field("text", at: \.text)
}

ConnectionType(MessageObject.self, as: "Message")

Query {
Field("chatObject", at: Resolver.chatObject)
}
}

XCTAssertEqual(
try schema.execute(
request: """
{
chatObject {
messages {
edges {
node {
id
text
}
}
}
}
}
""",
resolver: .init(),
context: NoContext(),
eventLoopGroup: eventLoopGroup
).wait(),
.init(
data: [
"chatObject": [
"messages": [
"edges": [
[
"node": [
"id": 1,
"text": "a",
],
],
[
"node": [
"id": 2,
"text": "b",
],
],
],
],
],
]
)
)
}
}

0 comments on commit 64b180e

Please sign in to comment.