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
26 changes: 13 additions & 13 deletions Examples/HelloWorldServer/Sources/HelloWorldServer/Resolvers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import GraphQL
import GraphQLGeneratorRuntime

// Must be created by user and named `GraphQLContext`.
/// Must be created by user and named `GraphQLContext`.
class GraphQLContext: @unchecked Sendable {
// User can choose structure
var users: [String: User]
Expand All @@ -22,8 +22,8 @@ class GraphQLContext: @unchecked Sendable {
}
}

// Scalars must be represented by a Swift type of the same name in the GraphQLScalars namespace, conforming to
// the GraphQLScalar protocol
/// Scalars must be represented by a Swift type of the same name in the GraphQLScalars namespace, conforming to
/// the GraphQLScalar protocol
extension GraphQLScalars {
struct EmailAddress: GraphQLScalar {
let email: String
Expand All @@ -32,7 +32,7 @@ extension GraphQLScalars {
self.email = email
}

// Codability conformance. Required for usage in InputObject
/// Codability conformance. Required for usage in InputObject
init(from decoder: any Decoder) throws {
email = try decoder.singleValueContainer().decode(String.self)
}
Expand All @@ -41,7 +41,7 @@ extension GraphQLScalars {
try email.encode(to: encoder)
}

// Scalar conformance. Not necessary, but default methods are very inefficient.
/// Scalar conformance. Not necessary, but default methods are very inefficient.
static func serialize(this: Self) throws -> Map {
return .string(this.email)
}
Expand All @@ -67,7 +67,7 @@ extension GraphQLScalars {
}
}

// Now create types that conform to the expected protocols
/// Now create types that conform to the expected protocols
struct Resolvers: GraphQLGenerated.Resolvers {
typealias Query = HelloWorldServer.Query
typealias Mutation = HelloWorldServer.Mutation
Expand All @@ -82,7 +82,7 @@ struct User: GraphQLGenerated.User {
let age: Int?
let role: GraphQLGenerated.Role?

// Required implementations
/// Required implementations
func id(context _: GraphQLContext, info _: GraphQL.GraphQLResolveInfo) async throws -> String {
return id
}
Expand All @@ -105,10 +105,10 @@ struct User: GraphQLGenerated.User {
}

struct Contact: GraphQLGenerated.Contact {
// User can choose structure
/// User can choose structure
let email: String

// Required implementations
/// Required implementations
func email(context _: GraphQLContext, info _: GraphQL.GraphQLResolveInfo) async throws -> GraphQLScalars.EmailAddress {
return .init(email: email)
}
Expand All @@ -121,7 +121,7 @@ struct Post: GraphQLGenerated.Post {
let content: String
let authorId: String

// Required implementations
/// Required implementations
func id(context _: GraphQLContext, info _: GraphQL.GraphQLResolveInfo) async throws -> String {
return id
}
Expand All @@ -140,7 +140,7 @@ struct Post: GraphQLGenerated.Post {
}

struct Query: GraphQLGenerated.Query {
// Required implementations
/// Required implementations
static func user(id: String, context: GraphQLContext, info _: GraphQL.GraphQLResolveInfo) async throws -> (any GraphQLGenerated.User)? {
return context.users[id]
}
Expand All @@ -163,7 +163,7 @@ struct Query: GraphQLGenerated.Query {
}

struct Mutation: GraphQLGenerated.Mutation {
// Required implementations
/// Required implementations
static func upsertUser(userInfo: GraphQLGenerated.UserInfo, context: GraphQLContext, info _: GraphQLResolveInfo) -> any GraphQLGenerated.User {
let user = User(
id: userInfo.id,
Expand All @@ -178,7 +178,7 @@ struct Mutation: GraphQLGenerated.Mutation {
}

struct Subscription: GraphQLGenerated.Subscription {
// Required implementations
/// Required implementations
static func watchUser(id: String, context: GraphQLContext, info _: GraphQLResolveInfo) async throws -> AnyAsyncSequence<(any GraphQLGenerated.User)?> {
return AsyncStream<(any GraphQLGenerated.User)?> { continuation in
context.onTriggerWatch = { [weak context] in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import GraphQL
import Testing

@testable import HelloWorldServer
import Testing

@Suite
struct HelloWorldServerTests {
Expand Down
18 changes: 14 additions & 4 deletions Sources/GraphQLGeneratorCore/Utilities/SafeNameGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ struct DefensiveSafeNameGenerator: SafeNameGenerator {
}

extension SafeNameGenerator where Self == DefensiveSafeNameGenerator {
static var defensive: DefensiveSafeNameGenerator { DefensiveSafeNameGenerator() }
static var defensive: DefensiveSafeNameGenerator {
DefensiveSafeNameGenerator()
}
}

/// Returns a string sanitized to be usable as a Swift identifier, and tries to produce UpperCamelCase
Expand All @@ -129,8 +131,14 @@ struct IdiomaticSafeNameGenerator: SafeNameGenerator {
/// The defensive strategy to use as fallback.
var defensive: DefensiveSafeNameGenerator

func swiftTypeName(for documentedName: String) -> String { swiftName(for: documentedName, capitalize: true) }
func swiftMemberName(for documentedName: String) -> String { swiftName(for: documentedName, capitalize: false) }
func swiftTypeName(for documentedName: String) -> String {
swiftName(for: documentedName, capitalize: true)
}

func swiftMemberName(for documentedName: String) -> String {
swiftName(for: documentedName, capitalize: false)
}

private func swiftName(for documentedName: String, capitalize: Bool) -> String {
if documentedName.isEmpty { return capitalize ? "_Empty_" : "_empty_" }

Expand Down Expand Up @@ -302,5 +310,7 @@ struct IdiomaticSafeNameGenerator: SafeNameGenerator {
}

extension SafeNameGenerator where Self == DefensiveSafeNameGenerator {
static var idiomatic: IdiomaticSafeNameGenerator { IdiomaticSafeNameGenerator(defensive: .defensive) }
static var idiomatic: IdiomaticSafeNameGenerator {
IdiomaticSafeNameGenerator(defensive: .defensive)
}
}
4 changes: 2 additions & 2 deletions Tests/GraphQLGeneratorCoreTests/IndentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import Testing

@Suite
struct IndentTests {
@Test func singleLine() async throws {
@Test func singleLine() {
#expect("abc".indent(1, includeFirst: false) == "abc")
#expect("abc".indent(1, includeFirst: true) == " abc")
#expect("abc".indent(2, includeFirst: true) == " abc")
}

@Test func multiLine() async throws {
@Test func multiLine() {
#expect(
"""
abc
Expand Down
2 changes: 1 addition & 1 deletion Tests/GraphQLGeneratorCoreTests/SchemaGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Testing
struct SchemaGeneratorTests {
let generator = BuildGraphQLSchemaGenerator()

@Test func generateSchema() async throws {
@Test func generateSchema() throws {
let bar = try GraphQLObjectType(
name: "Bar",
description: "bar",
Expand Down
10 changes: 5 additions & 5 deletions Tests/GraphQLGeneratorCoreTests/TypeGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct TypeGeneratorTests {

// MARK: - Enum Tests

@Test func generateEnum() async throws {
@Test func generateEnum() throws {
let actual = try generator.generateEnum(
for: .init(
name: "Foo",
Expand Down Expand Up @@ -137,7 +137,7 @@ struct TypeGeneratorTests {
#expect(result == expected)
}

@Test func generateInterfaceProtocol() async throws {
@Test func generateInterfaceProtocol() throws {
let interfaceA = try GraphQLInterfaceType(
name: "A",
description: "A"
Expand Down Expand Up @@ -184,7 +184,7 @@ struct TypeGeneratorTests {
)
}

@Test func generateTypeProtocol() async throws {
@Test func generateTypeProtocol() throws {
let interfaceA = try GraphQLInterfaceType(
name: "A",
description: "A"
Expand Down Expand Up @@ -248,7 +248,7 @@ struct TypeGeneratorTests {
)
}

@Test func generateRootTypeProtocolForQuery() async throws {
@Test func generateRootTypeProtocolForQuery() throws {
let bar = try GraphQLObjectType(
name: "Bar",
description: "bar",
Expand Down Expand Up @@ -329,7 +329,7 @@ struct TypeGeneratorTests {
#expect(result == expected)
}

@Test func generateRootTypeProtocolForSubscription() async throws {
@Test func generateRootTypeProtocolForSubscription() throws {
let subscription = try GraphQLObjectType(
name: "Subscription",
fields: [
Expand Down